简体   繁体   English

Azure Devops:如何将变量从代理作业传递到无代理作业?

[英]Azure Devops: How to pass variable FROM agent job TO agentless job?

I have a pipeline with 2 jobs.我有一个有 2 个工作的管道。

  1. CheckoutAndDeploy (standard agent job) CheckoutAndDeploy(标准代理作业)
  2. WaitDeployStatus (agentless) WaitDeployStatus(无代理)

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.

相关问题 Enabling An AgentJob to run Depending on a previous agent and agentless job in Azure Devops 运行 - Enabling An AgentJob to run Depending on a previous agent and agentless job in Azure Devops 从无代理作业设置 output 变量 - Set an output variable from an agentless job 如何在工件条件下在 Azure DevOps 中运行代理作业 - How to run agent job in Azure DevOps on artifact conditions Azure DevOps 中的代理作业和部署组作业有什么区别? - What are the differences between an Agent Job and a Deployment Group Job in Azure DevOps? Azure DevOps yaml 管道 - 从一个作业到另一个作业的输出变量 - Azure DevOps yaml pipeline - output variable from one job to another 在Azure DevOps中的Release管道中的作业代理的两个任务之间共享PowerShell变量 - Share PowerShell variable between two tasks of the job agent in Release pipeline in Azure DevOps Azure DevOps 代理作业自动选择池:&#39;Hosted Ubuntu 1604&#39; - Azure DevOps Agent Job automatically select Pool: 'Hosted Ubuntu 1604' 我们可以暂停 azure devops 代理作业并等待回调吗 - Can we pause an azure devops agent job and wait for callback Azure DevOps Pipelines,作业如何知道它是从计划中触发的? - Azure DevOps Pipelines, how can the job know it was triggered from a Schedule? 如何在 Azure Devops Pipeline 中使用 PowerShell 根据条件触发代理作业 - How to trigger Agent Job As per condition using PowerShell in Azure Devops Pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM