Debasis Ghosh
Debasis Ghosh

Reputation: 263

How to pass powershell script variable values to downstream task in Release pipeline

Created a CD with few steps starting from "Azure PowerShell Task".

In Azure PowerShell tasks, executing a PowerShell script file and set a value in a variable. At the end of the script I have set the variable with a value –

echo "##vso[task.setvariable variable=myvariable;isSecret=false;isOutput=true;]myvalue"

myvariable is the variable

myvalue is the value.

Based on the value of “myvariable”; downstream task will be executed or skipped. Mentioned "Custom Condition" in downstream task (Task - Azure Create or Update Resource) –

and(succeeded(), eq(variables[‘myvariable’], ‘myvalue’))

But, it’s always skipping the step; despite the correct value is passing. Here is my release tasks snippet - enter image description here

How do I overcome?

Upvotes: 1

Views: 3310

Answers (2)

Debasis Ghosh
Debasis Ghosh

Reputation: 263

Thanks everyone for your valuable input. Resolution - PowerShell Script -

$myvalue="hello"
Write-Host "##vso[task.setvariable variable=myvariable]$myvalue"

Assign value ("hello") in a variable ($myvalue), then set it in "Write-Host". Direct value did not work for me. Now we can use/verify "myvariable" value in downstream tasks in Custom Condition as mentioned by @Alex KeySmith.

and(succeeded(), eq(variables['myvariable'], 'hello'))

task -

enter image description here

Works in Build and Release pipeline.

Upvotes: 1

Alex KeySmith
Alex KeySmith

Reputation: 17101

try

Write-Host "##vso[task.setvariable variable=myvariable;isSecret=false;isOutput=true;]myvalue"

And then

and(succeeded(), eq(variables['myvariable'], 'myvalue'))

In the second part, the code you pasted in has the incorrect quote types, you had curly quotes ‘ ’ rather than the normal straight quotes ' '

You often end up with the wrong quotes if copying / pasting from Word or Outlook. I'm sure there's a proper a typography term for them.

Upvotes: 2

Related Questions