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.
# producer logged: ##vso[task.setvariable variable=imageTag;isOutput=true]v42
# consumer condition evaluated against an empty string and skippedCommon 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.
jobs:
- job: build
steps:
- bash: echo "##vso[task.setvariable variable=imageTag;isOutput=true]v42"
name: setTagRead it via stageDependencies in a dependent stage
Reference the full path and ensure the stage dependsOn the producer.
- 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
dependencieswithin a stage andstageDependenciesacross stages. - Declare an explicit
dependsOnwhenever you read another stage’s outputs.