1
votes

I have Azure DevOps release pipeline job having 4 tasks inside it.

I would like to set the environment variable in the first task and to use that value as input to the second task for parameter: Display name.

We can assume all 4 steps are PowerShell scripts.

Task 1 Powershell:

Write-Host "##vso[task.setvariable variable=myvariable;]abcdefg"

Task 2 Powershell: task2

PowerShell inside task 2:

Write-Host "$(myvariable)"

How could I set a variable in task 1 and access it as an input variable to task2?

My output was:

Task2 - $(myvariable) as display name

but PowerShell script itself output was:

abcdefg

1
"How could I set a variable in task 1 and access it as an input variable to task2?" correct me if i see this wrong but your setup already answers this question. i am not sure what you are asking hereD.J.
@D.J. Display name of task 2 should be "Task2 - abcdefg", but actually it is "Task2 - $(myvariable)".ldragicevic
possibly task names do not support dynamic interpolation4c74356b41

1 Answers

2
votes

Write-Host "##vso[task.setvariable variable=myvariable;]abcdefg"

That's because the variable this script created is not a pre-defined variable.

As the execution logic, after you queue the pipeline, you can see that the pipeline name, task name are displayed firstly, even though the script does not be executed. So, if these names are using variable to define them, the variable just can get the value from the pre-defined variable. Because the compile of variable value get in pipeline/task name are always firstly than the script executed.

In addition, the script in task just create a script variable, and this script variable only live for the lifetime of the Phase and are destroyed after execution.

How could I set a variable in task 1 and access it as an input variable to task2?

As you what want, if get it in another script, just use $(xxx) or $env:xxx. But, for name, $() just can get the pre-defined variable value, instead of the script variable value.