简体   繁体   中英

Azure DevOps Release Pipeline - How to set and pass values in variables in pipeline with Azure Powershell

With Azure Release Pipeline, in a task using the PowerShell Script, I am able to set values of variables and pass to next task using the command

Write-Host '##vso[task.setvariable variable=varResourceExists;isOutput=true;something'

However, when I put this similar command in a task that uses Azure PowerShell, this command is no longer allowed, the task produces a warning:

2019-10-22T00:23:14.3080614Z ##[warning]'##vso[task.setvariable variable=varResourceExists;isOutput=true;something' contains logging command keyword '##vso', but it's not a legal command. Please see the list of accepted commands: https://go.microsoft.com/fwlink/?LinkId=817296

As a result, the variable varResourceExists cannot be set by my task. I have also tried a conventional PowerShell set value by doing

$varResourceExists = 'something'; # this also does not work

Is there a way I can set this value in Azure Powershell script so that the next task can reference it?

##vso[task.setvariable variable=varResourceExists;isOutput=true;something is not correct syntax. You're missing a closing ] .

It should be ##vso[task.setvariable variable=varResourceExists;isOutput=true;]something

Here is how I solved my topic. In the pipeline Azure PowerShell task, I can have code such as Write-Host '##vso[task.setvariable variable=varResourceExists;isOutput=true;]False';

In the Output Variable option, I set a Reference Name "step1": Output Variable Then in the next step, I can do a conditional check using a Custom Condition: Custom Condition

I can also reference the variable in my code such as Write-Host "The step1.varResourceExists says: $(step1.varResourceExists)";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM