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: Download a file
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
Download a file
It is possible that you need external content that is not in your source repository to build or release your code. You can download these file from the web in the Inline Powershell task. There are multiple ways to this: Invoke-WebRequest, curl, wget, Start-BitsTransfer, System.Net.WebClient, etc. For this sample I used Invoke-WebRequest to download something from GitHub. If you have very large files, the Invoke-WebRequest is not the fastest method. When your file is large you can probably best use Start-BitsTransfer.
$output = [System.IO.Path]::GetTempFileName() Invoke-WebRequest -UseBasicParsing ` -Uri "https://raw.githubusercontent.com/user/repository/branch/filename" ` -OutFile $output
Now the file is saved on the $output location. You can use it in your process. If it is zipped you can unzip it with:
$outpath = "my path" [System.IO.Compression.ZipFile]::ExtractToDirectory($output, $outpath)
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
3 ways to download files with powershell
Invoke-WebRequest use basic parsing
When calling the Invoke-WebRequest you need to add the parameter -UseBasicParsing because the Internet Explorer engine is not configured on the build server. If you do not add that parameter you will see the following error:
The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer’s first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.