我正在尝试从多个连续阶段的一个阶段访问输出变量。
第一次访问变量时,我可以访问该值,但下次我尝试它是一个空字符串。
在下面的示例中B1打印'production'
但C1打印''
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)
日志如下所示:
// 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: ''