VSTS Powershell Commands

Tips and tricks Inline Powershell task VSTS, in this post VSTS/TFS command you can trigger from Powershell in your build or release pipeline

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: VSTS Powershell Commands.

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

VSTS Powershell Commands
From Powershell you are able to send commands to VSTS as you have seen in the earlier tips and tricks. This post gives an overview of availible commands. You have 3 areas you can send a command to: task, build and artifact. The general format format for the commands is:

##vso[area.action property1=value;property2=value;...]message

Area Task
logissue
The logissue action logs an error or warning to logging timeline of the task. The issue is reported in the build overview and the logs.

##vso[task.logissuetype=error;sourcepath=consoleapp/main.cs;linenumber=1;columnnumber=1;code=100;]this is an error

buildIssue

logdetail
Logdetail records are shown in the timeline of the task.

Write-Host "##vso[task.logdetail id=3ce154f2-6ac5-493b-8737-045f9bcb208b;name=project1;type=build;order=6]create new timeline record"
Write-Host "##vso[task.logdetail id=3ce154f2-6ac5-493b-8737-045f9bcb208c;parentid=3ce154f2-6ac5-493b-8737-045f9bcb208b;name=project1;type=build;order=7]create new timeline record2"
Write-Host "##vso[task.logdetail id=3ce154f2-6ac5-493b-8737-045f9bcb208b;progress=100;state=Complete;]update timeline record"

buildtimeline

addattachment
Uploads a file to the current timeline record in the task. You will be able to access the file later from the timeline.

##vso[task.addattachment type=myattachmenttype;name=myattachmentname;]c:\myattachment.txt

uploadsummary
Upload a summary to the current timeline record in the task.

##vso[task.uploadsummary]c:\testsummary.md

uploadfile
Upload a log file to the logs. This can be used to upload the logs from a command that executed.

##vso[task.uploadfile]c:\additionalfile.log

setprogress
Set the progress of the task. The progess will be updated when you monitor the task. Read more…

For ($i=0; $i -lt 100; $i++) {
    Write-Output "##vso[task.setprogress value=$i;]Log ouput"
    Start-Sleep -s 1
}

progress

complete
You can set the outcome of the task. With this you can change the flow of your pipeline. Read more…
result=Succeeded|SucceededWithIssues|Failed|Cancelled|Skipped

##vso[task.complete result=Succeeded;]DONE

setvariable
With setvariable you can set variable for later use. Read more…

##vso[task.setvariable variable=testvar;]testvalue

setendpoint
You can set an endpoint for later usage with setendpoint

##vso[task.setendpoint id=000-0000-0000;field=authParameter;key=AccessToken]testvalue

Area Artifact
associate
Create a artifact link in your build.

##vso[artifact.associate type=filepath;artifactname=MyFileShareDrop]\\MyShare\MyDropLocation

upload
Upload an artifact in your project.

##vso[artifact.upload containerfolder=testresult;artifactname=uploadedresult;]c:\testresult.trx

Area Build
uploadlog
Upload interesting logs to the ‘logs\tool’ container

##vso[build.uploadlog]c:\msbuild.log

updatebuildnumber
Update the build number of your current build.

##vso[build.updatebuildnumber]1.2.3.4

addbuildtag
Add tags to your build.

##vso[build.addbuildtag]Tag_UnitTestPassed

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

Resources
Git hub command documentation

3 thoughts on “VSTS Powershell Commands”

  1. Wow, this post has greatly improved my day! I have been looking for months for something to do with Files that are the output of Release Tasks, and by using the ##vso[task.uploadfile] command, it gives me exactly what i need – so money! Thank you!

    Like

Leave a comment

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