Pawan
Pawan

Reputation: 43

Accessing variables from one variable group to other in VSTS

As part of a POC, I am trying to set a environment variable in a powershell script from AgentPhase1 and trying to access and print the same variable in AgentPhase2 of a VSTS release pipeline. But, I always get below exception.

Exception Message: 'BuildConfiguration' is either empty or undefined

Is there any way to pass variables between multiple agent phases. My Code to set variable in AgentPhase1

$csv='1','2','3' Write-Host "##vso[task.setvariable variable=BuildConfiguration]$csv"

Code to fetch and print the variable in AgentPhase2

Write-Host 'Reading data from AgentPhase2' $env:BuildConfiguration

EDIT I am able to access and print 'BuildConfiguration' variable within the same Agent Phase, but I cannot read the same variable in other Agent Phases.

Any help...??

Upvotes: 1

Views: 1025

Answers (1)

Marina Liu
Marina Liu

Reputation: 38096

The changed value of the variable only works for the environment which you change the value, not other environments and AgentPhases.

The work around is add a Powershell task for each AgentPhase/environment which you need to get the changed value. The powershell script is the same as you set:

$csv='1','2','3'
Write-Host "##vso[task.setvariable variable=BuildConfiguration]$csv"

Upvotes: 1

Related Questions