How to read and set DevOps Pipeline variables using Azure PowerShell?

ε祈祈猫儿з 提交于 2019-12-11 09:07:32

问题


I have an Azure Pipeline setup with MyVariable variable defined:

How do I write Azure PowerShell Inline Script to read the variable, and set it to a value after some processing?


回答1:


Reading:

Variables are exposed as environment-variables, to read the variable "TestVar" you can do this:

$myScriptVariable = $env:TESTVAR

Note that "." will be replaced with "_" and all is uppercase.

Setting or Updating:

To set or update a variable you'll have to write following 'command' to the host with "write-host":

Write-Host "##vso[task.setvariable variable=testvar;]testvalue"

There are more logging-commands for different actions, i'll just leave the link to the documentation here -> https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md




回答2:


build variables are exposed as environment variables inside build steps, so you can just reference it using normal powershell syntax:

$env:MyVariable


来源:https://stackoverflow.com/questions/55129487/how-to-read-and-set-devops-pipeline-variables-using-azure-powershell

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