Skip to content
Latchkey

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 dependsOn the producer or dependencies.<job> is empty.
  • Cross-stage outputs use stageDependencies.<stage>.<job>.outputs[...], a different path than cross-job.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →