Azure Devops 输出变量未在阶段之间传递
Azure Devops Output Variable not being passed between stages
我正在尝试在阶段之间传递变量。我已经阅读了许多关于如何在阶段之间传递变量的正确语法的文档,但是 none 的语法似乎有效,此外还进行了多次其他尝试来寻找正确的语法。下面是我的 yml 文件和输出。
stages:
- stage: InitialStage
jobs:
- job: StandAlone
displayName: Required Stand Alone Job
pool: Releases
steps:
- bash: |
echo "##vso[task.setvariable variable=doThing;isOutput=true]Yes"
name: bash_test
- task: CmdLine@2
name: output_test
inputs:
script: |
echo "$(bash_test.doThing)"
- stage: CheckStage
dependsOn: InitialStage
jobs:
- job:
displayName: CheckStageJob
pool:
name: Releases
variables:
test1: $[ stageDependencies.InitialStage.StandAlone.output['bash_test.doThing'] ]
test2: $[ stageDependencies.InitialStage.output['StandAlone.bash_test.doThing'] ]
test3: $[ stageDependencies.InitialStage.StandAlone.output['StandAlone.bash_test.doThing'] ]
test4: $[ stageDependencies.InitialStage.output['bash_test.doThing'] ]
steps:
- task: CmdLine@2
name: test
inputs:
script: |
echo "$(test1)"
echo "$(test2)"
echo "$(test3)"
echo "$(test4)"
第一阶段输出:
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /opt/azagent01/_work/_temp/652819a6-cd0c-4e34-a2c3-2da1d3339ab1.sh
Yes
Finishing: output_test
第二阶段输出:
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /opt/azagent01/_work/_temp/bc144287-815e-4450-92e2-250cbbb92785.sh
Finishing: test
看起来你在定义变量时有语法错误。
At the job level, the format for referencing variables from a
different stage is
stageDependencies.STAGE.JOB.outputs['TASK.VARIABLE']
stages:
- stage: InitialStage
jobs:
- job: StandAlone
displayName: Required Stand Alone Job
steps:
- bash: |
echo "##vso[task.setvariable variable=doThing;isOutput=true]Yes"
name: bash_test
- task: CmdLine@2
name: output_test
inputs:
script: |
echo "$(bash_test.doThing)"
- stage: CheckStage
dependsOn: InitialStage
jobs:
- job:
displayName: CheckStageJob
variables:
test1: $[ stageDependencies.InitialStage.StandAlone.outputs['bash_test.doThing'] ]
test2: $[ stageDependencies.InitialStage.outputs['StandAlone.bash_test.doThing'] ]
test3: $[ stageDependencies.InitialStage.StandAlone.outputs['StandAlone.bash_test.doThing'] ]
test4: $[ stageDependencies.InitialStage.outputs['bash_test.doThing'] ]
steps:
- task: CmdLine@2
name: test
inputs:
script: |
echo "$(test1)"
echo "$(test2)"
echo "$(test3)"
echo "$(test4)"
输出:
Generating script.
Script contents:
echo "Yes"
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/f1a4da2e-b447-4e4a-a78a-6e39f2f5edeb.sh
Yes
Finishing: output_test
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/4d29ffb1-ba1a-41d1-b3d7-e89351c03493.sh
Yes
Finishing: test
我正在尝试在阶段之间传递变量。我已经阅读了许多关于如何在阶段之间传递变量的正确语法的文档,但是 none 的语法似乎有效,此外还进行了多次其他尝试来寻找正确的语法。下面是我的 yml 文件和输出。
stages:
- stage: InitialStage
jobs:
- job: StandAlone
displayName: Required Stand Alone Job
pool: Releases
steps:
- bash: |
echo "##vso[task.setvariable variable=doThing;isOutput=true]Yes"
name: bash_test
- task: CmdLine@2
name: output_test
inputs:
script: |
echo "$(bash_test.doThing)"
- stage: CheckStage
dependsOn: InitialStage
jobs:
- job:
displayName: CheckStageJob
pool:
name: Releases
variables:
test1: $[ stageDependencies.InitialStage.StandAlone.output['bash_test.doThing'] ]
test2: $[ stageDependencies.InitialStage.output['StandAlone.bash_test.doThing'] ]
test3: $[ stageDependencies.InitialStage.StandAlone.output['StandAlone.bash_test.doThing'] ]
test4: $[ stageDependencies.InitialStage.output['bash_test.doThing'] ]
steps:
- task: CmdLine@2
name: test
inputs:
script: |
echo "$(test1)"
echo "$(test2)"
echo "$(test3)"
echo "$(test4)"
第一阶段输出:
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /opt/azagent01/_work/_temp/652819a6-cd0c-4e34-a2c3-2da1d3339ab1.sh
Yes
Finishing: output_test
第二阶段输出:
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /opt/azagent01/_work/_temp/bc144287-815e-4450-92e2-250cbbb92785.sh
Finishing: test
看起来你在定义变量时有语法错误。
At the job level, the format for referencing variables from a different stage is stageDependencies.STAGE.JOB.outputs['TASK.VARIABLE']
stages:
- stage: InitialStage
jobs:
- job: StandAlone
displayName: Required Stand Alone Job
steps:
- bash: |
echo "##vso[task.setvariable variable=doThing;isOutput=true]Yes"
name: bash_test
- task: CmdLine@2
name: output_test
inputs:
script: |
echo "$(bash_test.doThing)"
- stage: CheckStage
dependsOn: InitialStage
jobs:
- job:
displayName: CheckStageJob
variables:
test1: $[ stageDependencies.InitialStage.StandAlone.outputs['bash_test.doThing'] ]
test2: $[ stageDependencies.InitialStage.outputs['StandAlone.bash_test.doThing'] ]
test3: $[ stageDependencies.InitialStage.StandAlone.outputs['StandAlone.bash_test.doThing'] ]
test4: $[ stageDependencies.InitialStage.outputs['bash_test.doThing'] ]
steps:
- task: CmdLine@2
name: test
inputs:
script: |
echo "$(test1)"
echo "$(test2)"
echo "$(test3)"
echo "$(test4)"
输出:
Generating script.
Script contents:
echo "Yes"
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/f1a4da2e-b447-4e4a-a78a-6e39f2f5edeb.sh
Yes
Finishing: output_test
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/4d29ffb1-ba1a-41d1-b3d7-e89351c03493.sh
Yes
Finishing: test