Azure Devops – not able to set variable in Powershell

As Levi Lu mentioned you can access pipeline variables in the next step. So if you set variables like this here:

enter image description here

$web ="some-web"
$app ="some-app"

Write-Host "##vso[task.setvariable variable=MyWebEnv;]$web"
Write-Host "##vso[task.setvariable variable=MyAppEnv;]$app"

then you can read them in this way:

enter image description here

Write-Host "Set Web to $(MyWebEnv)"
Write-Host "Set App to $(MyAppEnv)" 

enter image description here

And if you want to access them via env variables you should use this syntax:

Write-Host "Set Web to $($env:MYWEBENV)"
Write-Host "Set App to $($env:MYAPPENV)" 

Answer for EDIT 2:

What you actually need is output cross stage variables which is supported in YAML but not in classic pipelines. Please check this topics. You can overcome this but it requires an extra effort as it shown here. However, please remember that you can’t publish an artifact from release pipeline.

Here you have docs for cross stage variables but as above, it works on YAML.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top