Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline ansicolor console output

I know it's possible to display color in the console output using the AnsiColor plugin. I tested a basic example below:

// This shows a simple build wrapper example, using the AnsiColor plugin.
node {
    // This displays colors using the 'xterm' ansi color map.
    ansiColor('xterm') {
        // Just some echoes to show the ANSI color.
        stage "\u001B[31mI'm Red\u001B[0m Now not"
    }
}

However, this example is too basic and essentially hardcoded. Is it possible to utilize AnsiColor to make the entire console output color coded? For example, when I execute Nuget and MSBuild for a .NET project, I would like the console output to color code the warnings, errors, etc.

like image 477
ChipNugget Avatar asked Nov 07 '18 22:11

ChipNugget


1 Answers

The AnsiColor Plugin "adds support for ANSI escape sequences, including color, to Console Output" (https://wiki.jenkins.io/display/JENKINS/AnsiColor+Plugin). It merely acts as a wrapper so that the Jenkins Console Output correctly displays colors, the plugin itself does not add ANSI escape sequences nor colors to the Console Output.

A good example is with the Ansible Plugin for which "colorized output can be enabled with the argument 'colorized: true'" (https://wiki.jenkins.io/display/JENKINS/Ansible+Plugin#AnsiblePlugin-ColorizedOutput). The Ansible Plugin's colorized output requires the AnsiColor Plugin else the Jenkins Console Output is incapable of displaying the colors.

Colorized output without the AnsiColor Plugin wrapper:

stage('build'){
    node('master'){
        ...
        ansiblePlaybook colorized: true, installation: 'ansible2.5.11', inventory: 'inventory/hosts', playbook: 'playbooks/example.yml'
    }
}

**Ansible Plugin** colorized: true without **AnsiColor** wrapper

Colorized output with the AnsiColor Plugin wrapper:

stage('build'){
    node('master'){
        ...
        ansiColor('xterm') {
            ansiblePlaybook colorized: true, installation: 'ansible2.5.11', inventory: 'inventory/hosts', playbook: 'playbooks/example.yml'
        }
    }
}

**Ansible Plugin** colorized: true with **AnsiColor** wrapper

like image 89
masseyb Avatar answered Oct 05 '22 11:10

masseyb