Home Azure DevOps Pipeline Output
Post
Cancel

Azure DevOps Pipeline Output

Ever thought about visualising the output of your pipeline with color in Azure DevOps?

I wanted to create my custom What-if deployment - PowerShell as there is an issue with the Azure Firewall rules being scrambled and giving false-positives for changes at each run, rendering the output almost unreadable.

There’s built-in commands in Azure DevOps that can be used to produce colored output, sections and groups. Read more here: Azure DevOps Formatting Commands

These formatting commands are great! The output renders such as: Azure DevOps formatting commands

This acheives what we would like to see, however there’s only one little annoying thing, that is that there’s no informational (or success/verbose) command that we can use.

The green output is called “Section”, which does not start with the ##[section] which makes it harder to read in the log output of Azure DevOps in my opinion, or if we could remove the ##[error] / ##[warning] of the orange/red outputs. I would simply like to have my error text in the color of my choosing and without any prefixes.

The first thought that came to mind is that perhaps the write-host command with ForegroundColor might do the trick. However the rendered output from that command in Azure DevOps ends up like this: write-host Which is not what we were looking for.

I decided to test if the ANSI color codes would be rendered as documented here: ANSI Colors. To test this out, we create a yaml pipeline, as an example, the one below.

1
2
3
4
steps:
- pwsh: |
    $FormattedString = '{0}{1}{2}' -f "$([char]27)[32`m", 'Testing', "$([char]27)[0m"
    Write-output $FormattedString

And checking the rendered output in Azure DevOps you can see the following: ANSI Output We can see that it says ‘Testing’ in green! Checking the raw log we can also see this: ANSI Output - Raw log This means that the Azure DevOps portal do render ANSI colors, which is great!

After reviewing the wikipedia page regarding ANSI colors, we can also see that if we increase each color code by 10, it should also highlight the text with the color as a background color. Azure DevOps background and foreground colored

Seems we’re onto something!

We’re able to output colored text as we want, without any prefixes making it easier for a human to read. In this case I’ve also grouped the output in two sections, “ForegroundColored” and “BackgroundColored”.

This is a great feature if you want to gather output in groups, making it easier to navigate the output and just expand the groups you are interested in.

As I stated in the start, I’ve used this to build my own custom what-if deployment to render the Azure DevOps pipeline output humanly readable.

I’ll create a blogpost series on that but for now the code for the demo pipeline and PowerShell function can be found on my github: SebastianClaesson - AzureDevOpsPipelineDemo

A big thanks for reading and feel free to drop any comments below!

This post is licensed under CC BY 4.0 by the author.

PowerShell Azure Function - Managed identity & triggers/bindings

Azure DevOps Pipeline Agent Extension (Ubuntu) - Behind a web proxy.