I'm trying to access a variable from one stage in multiple consecutive stages.
In the first stage the variable has the correct value, but in all the following stages it becomes an empty string.
See also this post for more info
Any help would be appreciated
Thanks
Actually I fond more details, the variable is set to blank when de dependsOn does not point to the stage that sets the variable value, in the sample below, Stage A sets the variable, stage B depends on A and can use it, then in stage C that depends in B the variable value becomes blank.
stages:
- stage: A
jobs:
- job: JA
steps:
- script: |
echo "This is job Foo."
echo "##vso[task.setvariable variable=doThing;isOutput=true]Yes" #The variable doThing is set to true
name: DetermineResult
- script: echo $(DetermineResult.doThing)
name: echovar
- job: JA_2
dependsOn: JA
condition: eq(dependencies.JA.outputs['DetermineResult.doThing'], 'Yes')
steps:
- script: |
echo "This is job Bar."
#stage B runs if DetermineResult task set doThing variable n stage A
- stage: B
dependsOn: A
jobs:
- job: JB
variables:
varFromStageA: $[ stageDependencies.A.JA.outputs['DetermineResult.doThing'] ]
steps:
- bash: echo "Hello world stage B first job"
- script: echo $(varFromStageA)
#stage B runs if DetermineResult task set doThing variable n stage A
- stage: C
dependsOn: B
jobs:
- job: JC
variables:
varFromStageA: $[ stageDependencies.A.JA.outputs['DetermineResult.doThing'] ]
steps:
- bash: echo "Hello world stage B first job"
- script: echo $(varFromStageA)