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

不羁的心 提交于 2019-12-11 09:55:37

问题


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 -

How do I overcome?


回答1:


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.




回答2:


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 -

Works in Build and Release pipeline.



来源:https://stackoverflow.com/questions/53154702/how-to-pass-powershell-script-variable-values-to-downstream-task-in-release-pipe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!