Santosh Kumar
Santosh Kumar

Reputation: 53

How to set Variables in Release pipeline in Azure DevOps pipeline

I have searched all the documents about how to set variables to pass the variable during the run time build pipeline and only told me how to set in .yaml. But how to use it in release pipeline runtime variables?

Suppose I have a Generate-manifest.ps1 file which I will run to generate manifest.json file which representing the latest release packages with version number inside it. Version: 1.0.0. This version value should passed as a variable during runtime. I need help to do this.

enter image description here

Manifest.json file looks like this.:

{
"version":  "1.0.0",
"timeStamp":  "2021-05-07T09:41:34+00:00",
"packages":  [
                 {
                     "name":  "data-service",
                     "type":  "docker-image",
                     "version":  "REL-1.0.5367"
                 },
                 {
                     "name":  "feedback-service",
                     "type":  "docker-image",
                     "version":  "REL-1.0.6099"
                 },
             ]
 }

Upvotes: 0

Views: 2753

Answers (1)

GeralexGR
GeralexGR

Reputation: 3582

Based on your explanation I understand that you need to read version variable during the build pipeline and pass this variable on the release pipeline in order to use it on BuildNumber for example.

First you will need to use a powershell task to read the version value from the .json file.

$deployment_config = Get-Content manifest.json -raw | ConvertFrom-Json
$versionNumber = $deployment_config.version

Then you can change the BuildNumber variable on build pipeline

$buildnumber = -join("v",$versionNumber ,"_","$(Build.BuildNumber)")

And also update

Write-Host "##vso[build.updatebuildnumber]$buildnumber"

You can then use the varialbe $(Build.BuildNumber) on release pipeline

release pipeline

Upvotes: 1

Related Questions