如何覆盖管道变量或如何从作业创建管道变量?
我正在运行一个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)"但是,在下一个作业中,GIT_TAG具有v0.0.1的初始值。
发布于 2020-01-26 07:26:06
默认情况下,如果您覆盖一个变量,则该值仅适用于他的作业,而不是序列作业。
在同一阶段在作业之间传递变量要复杂一些,因为它需要处理输出变量。
类似于上面的示例,要传递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)更多信息,你可以找到这里。
https://stackoverflow.com/questions/59914386
复制相似问题