Maximize how you use your VSTS build and release pipeline with Inline Powershell tasks. In this blog series ‘Tips and Tricks for Inline Powershell’, I will show simple samples on how to get more out of your pipelines. This blog post: Use VSTS Variables.
VSTS Inline powershell task
The Inline PowerShell VSTS task enables you to execute PowerShell from a textbox within your build or release pipeline. You can run a PowerShell script on you agent or as Azure Powershell.
Introduction Inline Powershell Task
Install Inline Powershell Task
Use VSTS Variables Inline Powershell
You can use variables to steer you VSTS Pipeline. These variable can be used, changed or created in your VSTS Inline Powershell task. You have access to your own variables and the default variables VSTS variable.
Reading/Using a variable
When you want to use a variable in your Inline Powershell script, you can add them in the arguments parameter field. For example the default variable Build.BuildNumber can be added by putting -buildnumber ($Build.BuildNumber) in the argument parameters. Then add it as Parameter to your script and you will be able to access the variable.
Param( [string]$buildNumber ) Write-Output "The buildnumber is:$buildNumber"
Create or save a changed variable
You can also set or modify a variable for usage by an other task. The command you can use is task.setvariable:
Write-Host "##vso[task.setvariable variable=variableName]variable value" Write-Host "##vso[task.setvariable variable=mySecret;issecret=true]tomatos are purple"
Add the ‘issecret=true’ to handle any secret values. When they are printed, they will be shown as *******.
More tips and tricks
Use VSTS variables
Let your task fail
VSTS Command overview
Call a WebHook
Download a file
Install a Powershell Module
Navigate VSTS as filesystem
Make VSTS API Rest calls
Script example: Act on failed build
See default list VSTS variables: Overview of default VSTS variables