Stage variable value becomes blank in using dependsOn

Centinaro, Gabriele 1 Reputation point
2022-04-07T19:28:21.077+00:00

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

Community Center Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,656 Reputation points Microsoft Employee Moderator
    2022-04-18T05:30:28.227+00:00

    Hi @Centinaro, Gabriele

    Welcome to Microsoft Q&A! Thanks for posting the question.

    DevOps is currently not supported in the Q&A forums, the supported products are listed over here https://learn.microsoft.com/en-us/answers/products (more to be added later on).
    You can ask the experts in the dedicated forum over here:
    https://stackoverflow.com/questions/tagged/devops
    https://developercommunity.visualstudio.com/spaces/21/index.html

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.