如何使用Azure PowerShell读取和设置DevOps Pipeline变量? [英] How to read and set DevOps Pipeline variables using Azure PowerShell?

查看:196
本文介绍了如何使用Azure PowerShell读取和设置DevOps Pipeline变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure管道设置,其中定义了MyVariable变量:

I have an Azure Pipeline setup with MyVariable variable defined:

如何编写Azure PowerShell内联脚本来读取变量,并在进行一些处理后将其设置为值?

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

推荐答案

阅读:

变量作为环境变量公开,要读取变量"TestVar",您可以执行以下操作:

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.

设置或更新:

要设置或更新变量,您必须使用"write-host"将以下命令"写入主机:

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

这篇关于如何使用Azure PowerShell读取和设置DevOps Pipeline变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆