Navigate VSTS project as filesystem from Inline Powershell

Tips and tricks Inline Powershell task VSTS, navigate VSTS/TFS like it is a filesystem

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: Navigate VSTS as filesystem

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

Navigate VSTS as filesystem
To get more out of your pipeline, it would be nice have a easy way to access you VSTS team project from Inline Powershell. The VSTeam Powershell module from Donovan Brown let you access the team information like:

Builds
Releases
Teams

The module let you access the information in a Simple Hierarchy in PowerShell (SHiPS). SHiPS let you access the information like it is a filesystem. You can navigate the filesystem with the following commands: Get-Item and Get-ChildItem which let query the information. To connect to the VSTS you need an access token. Create the token in you profile. You can select all kind of information, like build/release failures, starttime, requestedByUser. The following sample shows the information on a build:

Install-Module VSTeam -scope CurrentUser -Force
Add-Profile -Account '[VSTSOrTFSAccountName]' -PersonalAccessToken '[personalaccesstoken]' -Name '[ProfileName]'
New-PSDrive -Name vsteam -PSProvider SHIPS -Root 'VSTeam#VSAccount'
Get-PSDrive
cd vsteam:
dir
cd "Inline powershell samples"
dir
cd builds
dir
Get-ChildItem 386 | select *

build

When you have access to the build information you can use it in a WebHook, make a project work item or do an other action in your pipeline.

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
Navigate your visual studio team services projects like a file system
Use personal access tokens to authenticate
Github: PowerShell module for accessing TFS and VSTS
Powershell gallary: VSTeam module

Extra: Navigate Azure as SHiPS
AzurePSDrive module let you browse your AzureRM resources:

Install-Module AzurePSDrive   # will install SHiPS as its dependency
Import-Module AzurePSDrive
New-PSDrive -Name Azure -PSProvider SHiPS -root 'AzurePSDrive#Azure'
cd Azure:
PS Azure:\>dir

Navigate Azure resources just like a file system

Leave a comment

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