Rom*_*cea 0 azure-devops azure-pipelines
如何覆盖管道变量或如何从作业创建管道变量?
我正在运行一个prepare作业,我将当前的 git 标签提取到一个我在后续作业中需要的变量中,所以我决定创建一个管道变量并在第一个作业中覆盖它的值:
variables:
GIT_TAG: v0.0.1
jobs:
- job: job1
pool:
vmImage: 'ubuntu-16.04'
steps:
- powershell: |
Write-Host "##vso[task.setvariable variable=GIT_TAG]$(git describe --tags --always)"
Run Code Online (Sandbox Code Playgroud)
但是,在下一个作业GIT_TAG中的初始值为v0.0.1。
默认情况下,如果您覆盖变量,则该值仅适用于他的作业,而不适用于序列作业。
在同一阶段的作业之间传递变量有点复杂,因为它需要使用输出变量。
与上面的示例类似,传递FOO变量:
job: firstjobname: mystep;isOutput=true,例如:echo "##vso[task.setvariable variable=FOO;isOutput=true]some value"$[ dependencies.firstjob.outputs['mystep.FOO'] ](记住表达式用单引号)一个完整的例子:
jobs:
- job: firstjob
pool:
vmImage: 'Ubuntu-16.04'
steps:
# Sets FOO to "some value", then mark it as output variable
- bash: |
FOO="some value"
echo "##vso[task.setvariable variable=FOO;isOutput=true]$FOO"
name: mystep
# Show output variable in the same job
- bash: |
echo "$(mystep.FOO)"
- job: secondjob
# Need to explicitly mark the dependency
dependsOn: firstjob
variables:
# Define the variable FOO from the previous job
# Note the use of single quotes!
FOO: $[ dependencies.firstjob.outputs['mystep.FOO'] ]
pool:
vmImage: 'Ubuntu-16.04'
steps:
# The variable is now available for expansion within the job
- bash: |
echo "$(FOO)"
# To send the variable to the script as environmental variable, it needs to be set in the env dictionary
- bash: |
echo "$FOO"
env:
FOO: $(FOO)
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到更多信息。
| 归档时间: |
|
| 查看次数: |
2502 次 |
| 最近记录: |