4
votes

I created two PowerShell tasks in the Release pipeline in Azure DevOps. The first task contains an inline PowerShell script which looks like this:

$ciVersion = "v2.1"
Write-Host $ciVersion

In the second PowerShell task, I want only to read the variable which I declared in the first PowerShell task.

Write-Host $ciVersion

After I run the release process the console shows me the v2.1 in the console window of the first task but shows me nothing in the console window of the second task. I've also played with trying to declare an environment variable and modify its value in tasks but that didn't work for me as well. Any ideas? Cheers

1

1 Answers

6
votes

In the first PowerShell task set the variable as environment variable:

$ciVersion = "v2.1"
Write-Host $ciVersion
Write-Host ("##vso[task.setvariable variable=ciVersion;]$ciVersion")

In the second task read the variable in this way:

$ciVersion =  $env:ciVersion
Write-Host $ciVersion

This will do the work :)