Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an Azure Pipeline setup with MyVariable variable defined:

MyVariable

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

You can write your azure powershell scripts inline here.

like image 841
CSon Avatar asked Mar 12 '19 19:03

CSon


2 Answers

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

like image 171
D.J. Avatar answered Oct 17 '22 19:10

D.J.


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

$env:MyVariable
like image 43
4c74356b41 Avatar answered Oct 17 '22 19:10

4c74356b41