Azure Devops Pass Variables between Tasks
Today I wanted to see if it was possible to create a variable in Azure Devops, change the value within a Task and then use the updated value in a step further down the list of Tasks.
Turns out its pretty easy (when you get the syntax correct)
So I created a variable in Azure Devops called Version like so and set its value to 1.0
And then I want to make sure I can read this from a standard PowerShell Task in a step within my Build like so :-
Which when built showed me the value as I’d expect of 1.0
And then I want to set the variable to a new value (which could be from anything or anywhere to be honest) using the syntax
And then finally read out the current value by using $(Version)
Which shows the Version parameter has been updated to 1.2.3 as we would want.
Hope this helps someone at some point 🙂
Thanks man. Found it really useful.
Thanks, Greg! This made my day!!
typo in the first line it should be 0.1 and not 1.0
Well spotted thanks – I’ll fix 👌
This doesn’t work if you have the tasks in a Task Group, it kept the parrent variable value.
I tried the same steps, it doesn’t update the value.
This was really straight forward and helpful actually! Thanks
Thank you Gregor, this was very helpful!!
I have a scenario wherein I already have one string variable, with some content in it, in a Powershell task in my release pipeline and I want the value of this variable to be passed into another Powershell task.
$string1 = “foo”
Write-Host (‘##vso[task.setvariable variable=MyString]$string1’)
In my next Powershell task, I use Write-Host $(MyString) but it doesn’t show the right value. Any ideas what am I doing wrong here?
same for me – doesnt work