4

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 Answer 1

6

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.