Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing output variable more than once renders empty string

I'm trying to access an output variable from one stage in multiple consecutive stages.

The first time I access the variable I can access the value, but the next time I try it's an empty string.

In the example below B1 prints 'production' but C1 prints ''

trigger:
  - yaml-testing

pool:
  vmImage: windows-2019

stages:
- stage: A
  jobs:
  - job: A1
    steps:
      - task:  InlinePowershell@1
        name: setvar
        inputs:
          Script: |
            Write-Host "##vso[task.setvariable variable=Environment;isOutput=true]production"

- stage: B
  dependsOn: A
  variables:
    Environment: $[ stageDependencies.A.A1.outputs['setvar.Environment'] ]
  jobs:
  - job: B1
    steps:
      - task:  InlinePowershell@1
        name: printvar1
        inputs:
          Script: |
            Write-Host 'B1' 
            Write-Host $(Environment)

- stage: C
  dependsOn: B
  variables:
    Environment: $[ stageDependencies.A.A1.outputs['setvar.Environment'] ]
  jobs:
  - job: C1
    steps:
      - task:  InlinePowershell@1
        name: printvar2
        inputs:
          Script: |
            Write-Host 'C1' 
            Write-Host $(Environment)   

Logs look like this:

// Stage: B
Job preparation parameters
Variables:
  Environment:
    Parsing expression: <stageDependencies.A.A1.outputs['setvar.Environment']>
    Evaluating: stageDependencies['A']['A1']['outputs']['setvar.Environment']
    Result: 'production'

// Stage: C
Job preparation parameters
Variables:
  Environment:
    Parsing expression: <stageDependencies.A.A1.outputs['setvar.Environment']>
    Evaluating: stageDependencies['A']['A1']['outputs']['setvar.Environment']
    Expanded: Null
    Result: ''
like image 944
Victor Avatar asked Jun 27 '26 14:06

Victor


1 Answers

The difference is that stage B has an explicit dependency on stage A, so it can find out A1's output. But stage C has no explicit dependency on stage A, so A1's output is not available.

Try changing stage C like this:

- stage: C
  dependsOn:
    - A
    - B
like image 182
Vince Bowdren Avatar answered Jul 01 '26 05:07

Vince Bowdren