Cpo Design

How to update variable from PowerShell step in VSTS

Pavel Svarc Wednesday, February 14, 2018 2:31 PM

It is presumed that You are familiar with VSTS release and therefore it is not included as part of this blog post.

First we need to define variable in VSTS release process

We define variable in release. For this example We will be using variable name environment with default value Blue. The final stage should look like below.

Initial verification of the step

In order to make sure what the value is actually set to we can add new PowerShell step that will print out the variable.


Write-Verbose "$(environment)" -verbose

Modification of the variable from Blue to Green

Now we have verified that the value is set up as default value, we can proceed with changing the value. We need to add another PowerShell where we will use command 

Write-Host "##vso[task.setvariable variable=environment]Green"

Verification of the change

In order to make sure that our value has indeed been successful, we will add another step into the release agent step and again run the same command as for the initial verification step. 

Note: You can copy the step using mouse


Write-Verbose "$(environment)" -verbose


Final step Create release and verify

Now we just need to create a release which will execute the steps. Again it is presumed You know how to create a release.

Once the execution has run, we can see in the logs for the release all new steps added and indeed the value has been updated.