4

I am using the release pipeline classic editor and have a requirement of passing an output variable generated in a task to multiple jobs in the same stage or to outside stages. Currently, this output variable is available only inside the same job and I have to write the same task in multiple jobs and stages and I feel it is a redundancy. Is there any way to implement it?.

mystack
  • 4,910
  • 10
  • 44
  • 75

1 Answers1

5

In the Classic editor, I am afraid that output variables in a different job is not feasible. Please refer to this document .

enter image description here

As a workaround , you can use variables across jobs and stages via variable groups.

First define the variable in the variable group, then update the variable group through rest api or azure cli, and replace the defined variable with the value of the variable generated by the task.

PUT https://dev.azure.com/{organization}/{project}/_apis/distributedtask/variablegroups/{groupId}?api-version=5.1-preview.1

Here is a case about update variable group with powershell script.

Another workaround : You can share values across all of the stages by using release pipeline variables. The solution is updating the Release Definition for the Release Pipeline variable in the Stage where the variable is set.

  • Define a variable in the release definition Variable.
  • Use REST API Definitions - Update to update the value of the release definition variable in the agent job.
  • Use the updated value of the release definition variable in the next agent job.

The details info about using REST API to update the value of the release definition variable, you can follow this ticket.

For detailed steps and guide, please refer to this blog .

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • I am using a different method with PAT token, from the CI build i am triggering the release with updated variable. – mystack Jun 02 '20 at 11:38