Aakash Uniyal
Aakash Uniyal

Reputation: 1559

VSTS : Can I access the Build variables from Release definition?

In VSTS CI/CD , I am setting some variable's value in a Powershell task in CI. During CD I want to access that variable's value to do something , lets say echo.

Is this possible? If so, how?

Upvotes: 8

Views: 8388

Answers (3)

lg2de
lg2de

Reputation: 736

Check out the Azure DevOps extension Variable Tools for Azure DevOps Services.

In the "build pipeline" you can create a JSON file using "save variables". This file needs to be published as artifact or with existing artifact.

In the "release pipeline" you can restore the variables using "load variables" from the JSON file.

Upvotes: 3

Marina Liu
Marina Liu

Reputation: 38136

For VSTS itself, it can not persists variables from build to release.

An workaround is store the variable’s value in Variable Group and link the variable group into your release definition. Detail steps as below:

  • During build, you can Add a variable group with the name group-$(Build.BuildId), and store the variable you want to transfer in the variable group.

  • During release, you can get variable groups firstly, and filter the variable under the variable group-$(Build.BuildId). And delete the group group at the end of the release.

Besides, if artifact type is build for your release definition, you can also store the variable value in a file and then publish the file as build artifacts (as Calidus says).

Upvotes: 3

Calidus
Calidus

Reputation: 1414

You could write it out to a json/xml file and include that file in your published artifacts of your build defintion. Then read in that file via PowerShell in your release definition.

ConvertTo-Json | Out-File "file.json"
Get-Content "file.json" | ConvertFrom-Json

Upvotes: 6

Related Questions