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: ''