How to Pass a Variable Between Jobs in Azure Pipelines
Azure Pipelines moves a value across jobs by emitting an output variable and referencing it through dependencies.
In the producer, set the variable with isOutput=true on a named step. In a job that dependsOn the producer, read it via dependencies.<job>.outputs[...] and map it.
Output variable across jobs
The producer marks the variable as output; the consumer maps it from the dependency outputs.
azure-pipelines.yml
jobs:
- job: producer
pool: { vmImage: 'ubuntu-latest' }
steps:
- script: echo "##vso[task.setvariable variable=appVersion;isOutput=true]1.4.2"
name: setVar
- job: consumer
dependsOn: producer
pool: { vmImage: 'ubuntu-latest' }
variables:
version: $[ dependencies.producer.outputs['setVar.appVersion'] ]
steps:
- script: echo "Deploying $(version)"Gotchas
- The producing step must have a
name:- the output is referenced as<stepName>.<varName>. - The consumer must
dependsOnthe producer ordependencies.<job>is empty. - Cross-stage outputs use
stageDependencies.<stage>.<job>.outputs[...], a different path than cross-job.
Related guides
How to Set a Variable in Azure PipelinesSet variables in Azure Pipelines with the variables: block and dynamically at runtime via the logging command…
How to Publish Build Artifacts in Azure PipelinesPublish build artifacts in Azure Pipelines with PublishPipelineArtifact and download them in a later job with…