Is it possible to set an VSTS Build variable in a Build Step so that the value can be used in a subsequent Build Step?

Simian picture Simian · Oct 1, 2015 · Viewed 15.6k times · Source

I'm currently using Build in Visual Studio Team Services (was Visual Studio Online), and would like to be able to set a Build Variable in a Build Step so that the new value can be used in a subsequent Build Step.

Obviously you can set it before the Build starts but I'm looking to late bind the variable during a subsequent Build Step.

Is this possible?enter image description here

Answer

When inside of a script you can update a variable by emitting the following in your ps1

"##vso[task.setvariable variable=testvar;]testvalue"

You can then pass the variable into the next script using $(testvar)