I’ve been doing a lot with Azure Functions, Storage and DevTest Labs recently and leverage VSTS Build and Release to act as an ‘orchestration engine’ to automate Azure. It’s easy to have all my Azure Powershell scripts and ARM templates stored & versioned with VSTS. Even better is each checkin automatically firing off a build (with continuous integration setup) to run the scripts against Azure to ensure everything is working!
The one downside I’ve found is the logs – I get a huge text log and have to dig through to figure out what happened… I recently learned about special ‘tags’ in VSTS, so dig through logs no longer!
The logs in Visual Studio Team Services are parsed automatically – if you know a little about the parser we can use it to our advantage! Here’s a table of ‘tags’ and effects:
- ##[error] : Highlight the line in the log red
- ##[warning] : Highlight the line in the log orange
- ##[section] : Highlight the line in the log green
- ##[command] : Highlight the line in the log blue
- ##[debug] : Highlight the line in the log gray (or purple)
There are also the VSTS Tasks you can use as well! Details on those tags are listed here: https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md . There are some great ones at the link, but here are a few examples of what I’ve used in my Azure Powershell scripts:
- ##vso[task.logissue type=warning;] : Log a warning that gets reported to the build summary page
- ##vso[task.logissue type=error;] : Log an error that gets reported to the build summary page
##vso[task.setvariable variable=testvar;]testvalue : Set a variable in one task that you can use in another task
##vso[build.uploadlog]local file path : Upload a log file from the machine to the build results, helps in diagnosing issues
Here’s a quick demo to set this up for yourself! First step is to log into VSTS. If you don’t already have an account – no problem, you can get started for free by going to https://visualstudio.microsoft.com/ and clicking '”Get started for free” under Visual Studio Team Services.
Next – pick your source mapping (in my case I just hit ‘continue’ to accept the defaults), then choose a template (I picked ‘Empty pipeline’ link at the top to build from scratch). If you need more info on the steps involved check out this documentation: https://docs.microsoft.com/en-us/vsts/pipelines/get-started-designer?view=vsts
Once you have a build pipeline ready, let’s add our first task. For this demonstration I’m using a basic Powershell task but you can use the same tags all over (console output from a basic command line tool, msbuild output, etc)!
In my case I’m using an inline powershell script as part of the demo – Here’s the script I used:
Write-Host "This is a standard log message!" Write-Host " --------------------------------- " Write-Host "These tags just colorize the logs to improve readability" Write-Host "##[section] This is colored green!" Write-Host "##[command] This is colored blue!" Write-Host "##[debug] This is colored gray!" Write-Host " --------------------------------- " Write-Host "These tags colorize the logs and are picked up by the build" Write-Host "##[warning] This is a warning!" Write-Host "##vso[task.logissue type=warning;]This is another warning" Write-Host "##[error] This is an error!" Write-Host "##vso[task.logissue type=error;]This is another error" Write-Error “Actually fail the build task…”
Here’s what I entered in the VSTS Powershell Task:
And the results of the build!
Hope this helps – if you’ve found any other tricks to use in build and release please comment below!
Thanks for the great article, I would definitely implement in my build.
Just a quick note, the title reads “Visual Studio Team System” while in fact should be “Visual Studio Team Services” as you called it later
Good call – I’ll fix that, thanks!!