Azure DevOps : while using Release Pipeline in classic mode, I'm not able to pass the value of a variable to other tasks

Viewed 28

I have to store the value of $pipeline.variables.res.value in new variable in release pipeline and then have to use that new variable in rest of the stages and tasks in release pipeline. I'm working with classic pipelines. I'm trying below code:

  Set-Variable -Name abc -Value $pipeline.variables.res.value
  Write-Host "New Value:" $abc
  Write-Host "##vso[task.setvariable variable=xyz;isoutput=true]$abc"
  Write-Host "New Value:" $abc

Output: Not able to see any xyz variable in release pipeline. Also, on calling below commands in different tasks, I'm not getting any value as an output.

Input: Write-Host "New Value:" $xyz
       Write-Host "New Value:" $abc

Output:2022-09-19T09:04:56.4561806Z New Value: 
       2022-09-19T09:04:56.4594657Z New Value: 

Please help in this.

1 Answers

Your example is not structured correctly. This will not work because of all instructions in one task:

Set-Variable -Name abc -Value $pipeline.variables.res.value
Write-Host "New Value:" $abc
Write-Host "##vso[task.setvariable variable=xyz;isoutput=true]$abc"
Write-Host "New Value:" $xyz

You have to consume your variable in a next task like:

TASK 1
  Set-Variable -Name abc -Value $pipeline.variables.res.value
  Write-Host "New Value:" $abc
  Write-Host "##vso[task.setvariable variable=xyz;isoutput=true]$abc"

TASK 2
  Write-Host "New Value: $(xyz)"

enter image description here

Related