I'm trying to write a VSTS/vNext release process to disable release targets from F5 load-balancer pools e.g.:
Disable-PoolMembers (logfile) [run on agent phase / Powershell script]
if that will cause an outage
ask for override [agentless phase]
if override
Disable-PoolMembers [run on agent phase / Powershell script]
Wait for Validation [agentless phase]
Enable-PoolMembers (logfile) [run on agent phase / Powershell script]
When my Disable-PoolMembers.ps1 detects that disabling the requested pool members would result in a pool with no available/enabled members it will set a vsts variable with:
Write-Output ("##vso[task.setvariable variable=OutageCondition;]true")
And then in the 'ask for override' agentless phase there is a custom condition of
and(succeeded(), eq(variables['OutageCondition'], 'true'))
But the override agentless phase never executes.
I've put in some inline powershell scripts in the various phases to show what the variable value is. In the Disable-PoolMembers phase I see that the OutageCondition value is set to true, but in the Enable-PoolMembers agent phase it is set to false. So it appears that variables set using logging commands only persist in the phase that they were set.
I have tried not defining the variable at all and setting it on the fly in the powershell script with the same results (value is set, within the phase; but is not available in subsequent phases). And I have tried setting the variable in VSTS as a Release scope and the variable is available in all phases at it's defined value, but it's Powershell-changed value is only available in the phase in which it is set.
Is this expected behavior: ##vso only effects values within the phase? Is there something I can do to make the change persist through subsequent phases? Is there a better approach?
Variables can not be persisted in another phase for now. The variable’s value will be used the original defined for the variable not you changed by Write-Host.
There is the issue for variables not persistent between phases, you can follow up.