VSTS Logging with PowerShell

in DevOps

One of the great things about the build and release system within Visual Studio Team Services (VSTS) is if you don't see a task within the provided library, you can always run your own PowerShell script to have it do exactly what you need. When it comes to writing PowerShell scripts, I'm a huge fan of logging (sometimes to a fault). Recently, I wrote a PowerShell script that utilizes the Team module to interact with the VSTS REST API. In the process, I wanted to log all the script was doing to the logs of the actual build and release. So, I wrote some Write-Verbose statements and waited for the logs to light up with all my pretty messages...and...nothing.

So I thought, well, how does one log to VSTS build and release with PowerShell? Well, I was determined to find out.

I first created an inline PowerShell script and added code to write to each PowerShell stream.

After the script ran, you can see below how each are logged into VSTS build and release. They are color coded in each image to see how they are logged.

As you can see, if you want to write a message, Write-Host or Write-Output are your choices. As you'd expect, Write-Warning gives you a warning message and Write-Error is considered a terminating error to the build and release (assuming you've left the default of 'Fail on Standard Error' in the PowerShell task as seen below).

And there you have it. That is how you can log to VSTS build and release from PowerShell.

Well done!