Norrin Rad
Norrin Rad

Reputation: 991

Azure DevOps Passing Variables

we are trying to create a DevOps pipeline where we generate a string in the first stage and we would like to store into a variable which can be used in subsequent stages, or in subsequent tasks within the same stage, is there a way to do this? For clarity the string is generated by querying an external api which returns a string value.

Hope that makes sense 🥳

Thanks in advance

Upvotes: 0

Views: 1128

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40543

Yes, you shoudl use logging command and mark is as output. Here you have an example

## azure-pipelines.yml
stages:

- stage: one
  jobs:
  - job: A
    steps:
    - task: Bash@3
      inputs:
          filePath: 'script-a.sh'
      name: setvar
    - bash: |
       echo "##vso[task.setvariable variable=skipsubsequent;isOutput=true]true"
      name: skipstep

- stage: two
  jobs:
  - job: B
    variables:
      - name: StageSauce
        value: $[ stageDependencies.one.A.outputs['setvar.sauce'] ]
      - name: skipMe
        value: $[ stageDependencies.one.A.outputs['skipstep.skipsubsequent'] ]
    steps:
    - task: Bash@3
      inputs:
        filePath: 'script-b.sh'
      name: fileversion
      env:
        StageSauce: $(StageSauce) # predefined in variables section
        skipMe: $(skipMe) # predefined in variables section
    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          echo 'Hello inline version'
          echo $(skipMe) 
          echo $(StageSauce) 

Upvotes: 1

Related Questions