我正试图从多个连续阶段中的一个阶段访问变量。
在第一阶段中,变量具有正确的值,但在接下来的所有阶段中,它都变为空字符串。
另请参阅此帖子了解更多信息
如有任何帮助,将不胜感激
感谢
事实上,我喜欢更多的细节,当de-dependsOn不指向设置变量值的阶段时,变量被设置为空,在下面的示例中,阶段A设置变量,阶段B依赖于A并可以使用它,然后在依赖于B的阶段C中,变量值变为空。
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)
#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)
您需要将阶段C更改为同时依赖A和B。A必须在dependencies列表中,才能使用阶段Dependencies变量。
...
#stage B runs if DetermineResult task set doThing variable n stage A
- stage: C
dependsOn: B
jobs:
...
...
#stage B runs if DetermineResult task set doThing variable n stage A
- stage: C
dependsOn:
- A
- B
jobs:
...