[英]Azure Devops: How to pass variable FROM agent job TO agentless job?
I have a pipeline with 2 jobs.我有一个有 2 个工作的管道。
In WaitDeployStatus (1) I am trying to use an agentless job with Invoke Rest API .在 WaitDeployStatus (1) 我试图使用Invoke Rest API的无代理作业。 In this step, I need to post on an URL, the URL requires OAuth authentication
在这一步,我需要发布一个URL,URL需要OAuth认证
I can get the OAuth token from the previous job (CheckoutAndDeploy) and set isOutput=true to make the var available for other jobs ( like described in the documentation ) but I am unable to use it in job 2.我可以从上一个作业 (CheckoutAndDeploy) 中获取 OAuth 令牌并设置 isOutput=true 以使 var 可用于其他作业( 如文档中所述),但我无法在作业 2 中使用它。
I already tried:我已经尝试过:
$(SOMEREF.ACCESS_TOKEN)"
$[ dependencies.Get_Access_Token.outputs['SOMEREF.ACCESS_TOKEN'] ]"
$[ dependencies.Get_Access_Token.CheckoutAndDeploy.outputs['SOMEREF.ACCESS_TOKEN'] ]"
$[ stageDependencies.CheckoutAndDeploy.outputs['SOMEREF.ACCESS_TOKEN'] ]"
To set the variable is a bash task with this code:设置变量是一个 bash 任务,代码如下:
TOKEN_RESQUEST=$(command_to_get_the_token)
echo "##vso[task.setvariable variable=ACCESS_TOKEN;isOutput=true]$TOKEN_REQUEST"
Then I use SOMEREF as a reference name to access the variable.然后我使用 SOMEREF 作为引用名称来访问该变量。
The below usage will be able to pass the runtime variables from agent job to agentless job:以下用法将能够将运行时变量从代理作业传递到无代理作业:
trigger:
- none
pool:
vmImage: ubuntu-latest
jobs:
- job: A #agent job
steps:
- bash: |
echo "A"
echo "##vso[task.setvariable variable=outputVar;isoutput=true]<Auth information here>"
name: passOutput
- job: B #agentless job
pool: server
dependsOn: A
variables:
myVarFromJobA: $[ dependencies.A.outputs['passOutput.outputVar'] ]
steps:
- task: InvokeRESTAPI@1
inputs:
connectionType: 'connectedServiceName'
serviceConnection: 'GetProjects'
method: 'GET'
headers: |
{
"Content-Type":"application/json",
"Authorization": "$(myVarFromJobA)"
}
waitForCompletion: 'false'
Auth passed, I can successfully get the results here: Auth通过了,我这里可以成功得到结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.