Use VSTS Variables Inline powershell in build and release pipelines

Tips and tricks Inline Powershell task VSTS, use VSTS/TFS variables in your task

vsts-inlinepowershell-inlinepowershellMaximize 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.
EnterPowerShellArguments

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
Set progress
Change buildnumber
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

Extra resources
See default list VSTS variables: Overview of default VSTS variables

2 thoughts on “Use VSTS Variables Inline powershell in build and release pipelines”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.