How do pass variables between tasks in VSTS pipeline? How do pass variables between tasks in VSTS pipeline? azure azure

How do pass variables between tasks in VSTS pipeline?


You can set a new variable in your powershell and then pass it to VSTS, so that it can be used in one of the next tasks, like this.

Write-Host "##vso[task.setvariable variable=sauce]crushed tomatoes"Write-Host "##vso[task.setvariable variable=secretSauce;issecret=true]crushed tomatoes with garlic"

This will create a new environment variable called 'sauce' (first example) with value 'crushed tomatoes'.

On your next task you can read it using $(sauce) in your task configuration screen or $env:sauce in a powershell script.

See https://docs.microsoft.com/en-us/vsts/build-release/concepts/definitions/release/variables?tabs=batch for more info about how to use it.


The suggestion by @Rodrigo Werlang would work, but the set variable would be scoped to the job the task setting it is in.As of today, this is a known limitation and is documented here.

To define or modify a variable from a script, use the task.setvariable logging command. Note that the updated variable value is scoped to the job being executed, and does not flow across jobs or stages. Variable names are transformed to upper-case, and the characters "." and " " are replaced by "_".