Click here to Skip to main content
15,169,085 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a simple test release pipeline with 2 stages with 1 powershell task in each stage.

reference: Define variables - Azure Pipelines | Microsoft Docs[^]

1st stage: I want to set a variable value, from what I understand I have to use this weird syntax.
I also set the Output Variable Reference name to : MyReferenceName

PowerShell :
$myVariable='potato'
Write-Host 'myVariable:'+ $myVariable
Write-Host "##vso[task.setvariable variable=MyOutputVariable;isOutput=true]$myVariable"


2nd stage: I want to use/consume that variable

PowerShell :
Write-Host 'reference:'+$(MyReferenceName.MyOutputVariable)




In the second stage, I cannot seems to resolve the variable.

Is this the way it should be done ?

What I have tried:

I've tried different type of variable name permutations.
Posted
Updated 8-Dec-20 6:20am

1 solution

In the second stage, it would suffice to just say:
Write-Host 'reference: $(MyOutputVariable)'
Since MyOutputVariable is the name of your variable and it is literally inserted where you place it, so inside the quotes. I'm not sure where MyReferenceName comes from, but it should be omitted.
The output should then be:
Write-Host 'reference: potato'
I'm also not sure what "isOutput=true" in the first stage means or does, but I think it can be omitted as well.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900