Vat*_*oni 5 azure devops azure-devops azure-devops-extensions azure-devops-rest-api
在我的 azure 发布管道中,我有 2 个代理作业,一个用于使用 power-shell 的 sql 部署,另一个用于使用 power-shell 的 kubernetes。如何在第一个代理作业中设置输出变量并使用 power-shell 在第二个代理作业中使用该变量。
用
Write-Output "##vso[task.setvariable variable=testvar;isOutput=true;]testvalue"
Run Code Online (Sandbox Code Playgroud)
然后引用输出变量,就好像它存在于未来的任务中一样。
$(taskreference.testvariable)
Run Code Online (Sandbox Code Playgroud)
可以在 powershell 脚本任务的输出部分设置任务引用名称:
但是当我阅读文档时,似乎还没有跨工作参考:
去做
我不确定我们将如何生成作业引用名称,因为此时我们没有作业链。
它应该是这样的:
Run Code Online (Sandbox Code Playgroud){DefinitionName}_{JobName}
所以现在这个变量只能在同一个 Job 中工作。
工作:
# Set an output variable from job A
- job: A
pool:
vmImage: 'vs2017-win2016'
steps:
- powershell: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value"
name: setvarStep
- script: echo $(setvarStep.myOutputVar)
name: echovar
# Map the variable into job B
- job: B
dependsOn: A
pool:
vmImage: 'ubuntu-16.04'
variables:
myVarFromJobA: $[ dependencies.A.outputs['setvarStep.myOutputVar'] ] # map in the variable
# remember, expressions require single quotes
steps:
- script: echo $(myVarFromJobA)
name: echovar
Run Code Online (Sandbox Code Playgroud)
如何在 azure 发布管道中跨代理作业使用输出变量
恐怕目前还没有办法直接在代理作业之间使用输出变量。
有一个相关的问题Variables set vialogging Commands are not permanent Between agent s,您可以跟进。
要解决此问题,您可以尝试以下解决方法:
有关使用 REST API 更新发布定义变量值的详细信息,您可以按照以下票证操作:
如何从发布任务修改 Azure DevOps 发布定义变量?
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
12826 次 |
| 最近记录: |