Currently I am building a pipeline that performs some actions on Azure. For example creating a Azure Storage Account. When doing this, I want to return some values from my Powershell script back into a variable of my Build Pipeline, so I can use this in another task.
After some searching I finally found out how to do this. I will explain with an example
First create an empty Build Definition and add 2 Powershell Tasks to it
In the first inline Powershell task add one line to write the initial value and the second line to override the value.
Write-host $env:OutputVar Write-Output ("##vso[task.setvariable variable=OutputVar;]UpdatedValueInScript")
You can set the variable by using the VSTS embedded functions.
The Write-Output acts as an executor for this
The second task just outputs the variable again
After that run the build