Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the variable value in TFS/AzureDevOps from Build to Release Pipeline?

I've defined a variable in my TFS/AzureDevops Build definition (say it's time) and assign the value using PowerShell task within my build definition.

Like,

Type: Inline Script.

Inline script:

$date=$(Get-Date -Format g);
Write-Host "##vso[task.setvariable variable=time]$date"

You can refer to this similar example

Now I want to get this value in my release definition pipeline. I configured this build definition as continuous deployment to my release definition.

My Question is

How can I get the value of time in my release definition using some other variable? Is this possible?

like image 259
Jayendran Avatar asked Sep 29 '18 12:09

Jayendran


People also ask

How do you pass a variable from pipeline to release pipeline?

In order to pass variables between your build and release pipelines you can create/export a file containing your variable on your build agent. This file should be exported as build artifact and then downloaded on the release pipeline.

How do you use output variables in Azure DevOps release pipeline?

Once the output variables are defined, you can then reference them just like any other pipeline variable. One of the most common methods is using macro syntax. To reference the foo variable defined above, for example, you could use $(foo) or in the form of [originating_task name]_[variable name] .

How is the variables in variable group accessed in Azure DevOps build release definition?

To use a variable group, open your pipeline. Select Variables > Variable groups, and then choose Link variable group. In a build pipeline, you see a list of available groups. In a release pipeline, for example, you also see a drop-down list of stages in the pipeline.


1 Answers

The is no official way to pass variables from Build to Release. The only way to accomplish this is to store the values in a file (json, xml, yaml, what have you) and attach that as a Build Artifact. That way you can read the file in the release and set the variable again.

Martin Hinshelwood seems to have gotten frustrated enough by this problem and turned that functionality into an extension for Azure DevOps Pipelines.

Tasks included

  • Variable Save Task - During your build you can save the variables to a json file stored with your other build assets
  • Variable Load Task - During your Release you can load the saved variables and gain access to them.
like image 189
jessehouwing Avatar answered Oct 12 '22 12:10

jessehouwing