Bash - Examples

JFrog Pipelines Documentation

ft:sourceType
Paligo

The Pipelines DSL for these Bash examples is available in this repository in the JFrog GitHub account. For more information about Bash pipeline steps, see Bash.

Perform a build activity

This is an example of how to use the Bash step to perform a build activity.

Bash step to build

- name: build
  type: Bash
  configuration:
    nodePool: my_node_pool
    environmentVariables:
      env1: value1
      env2:
        default: value2
        description: Example Variable
        values:
          - value2
          - value3
        allowCustom: false
    runtime:
      type: image
      image:
        auto:
          language: node
          versions:
            - "16"
    inputResources:
      - name: src
  execution:
    onExecute:
      - cd $res_src_resourcePath
      - npm install
      - mkdir -p testresults && mkdir -p codecoverage
      - $res_src_resourcePath/node_modules/.bin/mocha --recursive "tests/**/*.spec.js" -R mocha-junit-reporter --reporter-options mochaFile=testresults/testresults.xml
      - $res_src_resourcePath/node_modules/.bin/istanbul --include-all-sources cover -root "routes" node_modules/mocha/bin/_mocha -- -R spec-xunit-file --recursive "tests/**/*.spec.js"
      - $res_src_resourcePath/node_modules/.bin/istanbul report cobertura --dir codecoverage
      - save_tests $res_src_resourcePath/testresults/testresults.xml
    onSuccess:
      - send_notification mySlack "build completed"

Python in bash step

This is an example of how to use Python in a bash step.

Python

resources:
  - name: script
    type: GitRepo
    configuration:
      path: jfrog/sample-script
      gitProvider: myGithub
pipelines:
  - name: test_stepTestReports
    steps:
      - name: testReport
        type: Bash
        configuration:
          inputResources:
            - name: script
        execution:
          onExecute:
            - cd $res_script_resourcePath
            - ls
            - python -m py_compile calc.py
            - pip install --upgrade pip
            - hash -d pip
            - pip install pytest           
            - py.test --verbose --junit-xml test-reports/results.xml test_calc.py
          onComplete:
            - save_tests $res_script_resourcePath/test-reports/results.xml

runtime, environmentVariables, and inputSteps tags

This example uses the runtime, environmentVariables, and inputSteps tags:

pipelines:
  - name: api_steps
    steps:
      - name: api_steps
        type: Bash
        configuration:
          runtime:
            type: host
          environmentVariables:
            env1: value1
            env2: value2
        execution:
          onExecute:
            - touch cachefile.txt
            - add_cache_files cachefile.txt my_file

      - name: api_steps_2
        type: Bash
        configuration:
          runtime:
            type: host
          inputSteps:
            - name: api_steps
        execution:
          onExecute:
            - echo "step 2.."

  - name: api_steps_ProjectAdmin
    steps:
      - name: api_steps_ProjectAdmin
        type: Bash
        configuration:
          runtime:
            type: host
          environmentVariables:
            env1: value1
            env2: value2
        execution:
          onExecute:
            - touch cachefile.txt
            - add_cache_files cachefile.txt my_file

      - name: api_steps_ProjectAdmin_2
        type: Bash
        configuration:
          runtime:
            type: host
          inputSteps:
            - name: api_steps_ProjectAdmin
        execution:
          onExecute:
            - echo "step 2.."

affinityGroup and priority tags

This example uses the affinityGroup and priority tags:

pipelines:
  - name: S_WF_019
    steps:
      - name: S_WF_019_001
        type: Bash
        execution:
          onStart:
            - add_run_variables step_1_var="step_1"
          onExecute:
            - echo "step 1 is running"

      - name: S_WF_019_002
        type: Bash
        configuration:
          inputSteps:
            - name: S_WF_019_001
          affinityGroup: ag_foo
          priority: 4
        execution:
          onStart:
            - echo "step_4_var - ${step_4_var}"
            - if [ "$step_4_var" != "step_4" ]; then exit 1; fi
            - add_run_variables step_2_var="step_2"
          onExecute:
            - echo "step 2 is running"

      - name: S_WF_019_003
        type: Bash
        configuration:
          inputSteps:
            - name: S_WF_019_001
          affinityGroup: ag_foo
          priority: 1
        execution:
          onStart:
            - echo "step_1_var - ${step_1_var}"
            - if [ "$step_1_var" != "step_1" ]; then exit 1; fi
            - add_run_variables step_3_var="step_3"
          onExecute:
            - echo "step 3 is running"

      - name: S_WF_019_004
        type: Bash
        configuration:
          inputSteps:
            - name: S_WF_019_001
          affinityGroup: ag_foo
          priority: 3
        execution:
          onStart:
            - echo "step_3_var - ${step_3_var}"
            - if [ "$step_3_var" != "step_3" ]; then exit 1; fi
            - add_run_variables step_4_var="step_4"
          onExecute:
            - echo "step 4 is running"

      - name: S_WF_019_005
        type: Bash
        configuration:
          inputSteps:
            - name: S_WF_019_002
            - name: S_WF_019_003
            - name: S_WF_019_004
          affinityGroup: ag_foo
          priority: 4
        execution:
          onStart:
            - echo "step_6_var - ${step_6_var}"
            - if [ "$step_6_var" != "step_6" ]; then exit 1; fi
            - add_run_variables step_5_var="step_5"
          onExecute:
            - echo "step 5 is running"

      - name: S_WF_019_006
        type: Bash
        configuration:
          inputSteps:
            - name: S_WF_019_002
            - name: S_WF_019_003
            - name: S_WF_019_004
          affinityGroup: ag_foo
          priority: 2
        execution:
          onStart:
            - echo "step_2_var - ${step_2_var}"
            - echo "step_3_var - ${step_3_var}"
            - echo "step_4_var - ${step_4_var}"
            - if [ "$step_2_var" != "step_2" ]; then exit 1; fi
            - if [ "$step_3_var" != "step_3" ]; then exit 1; fi
            - if [ "$step_4_var" != "step_4" ]; then exit 1; fi
            - add_run_variables step_6_var="step_6"
          onExecute:
            - echo "step 6 is running"

      - name: S_WF_019_007
        type: Bash
        configuration:
          inputSteps:
            - name: S_WF_019_005
            - name: S_WF_019_006
          affinityGroup: ag_foo
          priority: 2
        execution:
          onStart:
            - echo "step_1_var - ${step_1_var}"
            - echo "step_2_var - ${step_2_var}"
            - echo "step_3_var - ${step_3_var}"
            - echo "step_4_var - ${step_4_var}"
            - echo "step_5_var - ${step_5_var}"
            - echo "step_6_var - ${step_6_var}"
            - if [ "$step_1_var" != "step_1" ]; then exit 1; fi
            - if [ "$step_2_var" != "step_2" ]; then exit 1; fi
            - if [ "$step_3_var" != "step_3" ]; then exit 1; fi
            - if [ "$step_4_var" != "step_4" ]; then exit 1; fi
            - if [ "$step_5_var" != "step_5" ]; then exit 1; fi
            - if [ "$step_6_var" != "step_6" ]; then exit 1; fi
          onExecute:
            - echo "step 7 is running"

chronological tag

This examples uses the chronological tag:

pipelines: 
  - name: bash_chronological
    steps: 
      - name: Start
        type: Bash
        execution: 
          onExecute: 
            - echo "It's a start."
      - name: Step1
        type: Bash
        configuration:
          chronological: true
          inputSteps: 
            - name: Start
        execution: 
          onExecute: 
            - add_run_variables step1=foo
      - name: Step2
        type: Bash
        configuration: 
          chronological: true
          inputSteps: 
            - name: Start
        execution: 
          onExecute: 
            - add_run_variables step2=bar
      - name: Step3
        type: Bash
        configuration: 
          chronological: true
          inputSteps: 
            - name: Start
        execution: 
          onExecute: 
            - add_run_variables step3=baz
      - name: Finish
        type: Bash
        configuration: 
          inputSteps: 
            - name: Step1
            - name: Step2
            - name: Step3
        execution: 
          onExecute: 
            - |
              echo "Step1: $step1"
              echo "Step2: $step2"
              echo "Step3: $step3"

timeoutSeconds tag

This example uses the timeoutSeconds tag:

pipelines:
  - name: pipelines_S_Bash_0023
    steps:
      - name: S_Bash_0023
        type: Bash
        configuration:
          timeoutSeconds: 10
        execution:
          onExecute:
            - sleep 3m