1

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?

12
  • Can you verify one step after the Azure PowerShell task that the myvariable get the myvalue? (add another task and print the myvariable value) Commented Nov 5, 2018 at 13:00
  • Created one powershell task and printing the value of $(myvariable). Showing error - The term 'myvariable' is not recognized. Tried to print Write-Host $myvariable, no values is printing. Commented Nov 5, 2018 at 13:08
  • can you try replacing the echo with Write-Host? Commented Nov 5, 2018 at 13:10
  • Tried earlier, but not getting the value Commented Nov 5, 2018 at 13:18
  • i think with powershell you should use $env:myvariable. also try your condition like so: $(myvariable), myvalue. also, worth nothing, you are probably trying to do something you are not supposed to do with this approach Commented Nov 5, 2018 at 13:22

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.