Skip to content
Latchkey

Azure Pipelines Cross-Stage Output Variable Is Empty

A value set in one stage reads as empty in a later stage. Cross-stage outputs need three things: the variable set with isOutput=true, an explicit dependsOn, and a stageDependencies.<Stage>.<Job>.outputs[...] reference - miss any one and you get a blank.

What this error means

A downstream stage consumes $[ stageDependencies... ] and the value is empty, so a condition never matches or a deploy uses the wrong target. The producing stage logged the value fine.

Azure DevOps
# producer logged: ##vso[task.setvariable variable=imageTag;isOutput=true]v42
# consumer condition evaluated against an empty string and skipped

Common causes

Variable not emitted as an output

Only ##vso[task.setvariable variable=x;isOutput=true] variables are visible outside the setting job. Without isOutput=true the value stays job-local.

Wrong reference path or missing dependsOn

Across stages you must use stageDependencies.<Stage>.<Job>.outputs['<stepName>.<var>'], and the consuming stage must dependsOn the producing stage, or the dependency data is not populated.

How to fix it

Emit the variable as an output with a named step

Give the step a name and set the variable with isOutput=true.

azure-pipelines.yml
jobs:
  - job: build
    steps:
      - bash: echo "##vso[task.setvariable variable=imageTag;isOutput=true]v42"
        name: setTag

Read it via stageDependencies in a dependent stage

Reference the full path and ensure the stage dependsOn the producer.

azure-pipelines.yml
- stage: Deploy
  dependsOn: Build
  variables:
    imageTag: $[ stageDependencies.Build.build.outputs['setTag.imageTag'] ]
  jobs:
    - job: d
      steps: [ { script: echo $(imageTag) } ]

How to prevent it

  • Always name the step that emits an output variable.
  • Use dependencies within a stage and stageDependencies across stages.
  • Declare an explicit dependsOn whenever you read another stage’s outputs.

Frequently asked questions

What causes "Cross-stage output empty"?
Only ##vso[task.setvariable variable=x;isOutput=true] variables are visible outside the setting job. Without isOutput=true the value stays job-local.
How do I fix Cross-stage output empty?
Give the step a name and set the variable with isOutput=true.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card