I have a pipeline with 3 stages, each one depends on the previous so the execution will start the first stage, then after completion of the first stage the second starts and after completion of the second stage the third one starts.
I have a variable which value is set n the first stage, I can use it in the second stage but then when starting the third stage the variable is empty, no more value.
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.
`code`
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) <----- This has the correct value "Yes"
#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) <----- This now has empty value ""
I am not sure what to do, if all stages after the first depend on the first the variable is always present with the value but as soon as a do another dependency that generates a third or more levels its value disappears.
Please advise, see code snippet below
Thanks