Jenkins pipeline ansicolor console output

大城市里の小女人 提交于 2020-01-03 17:42:28

问题


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.


回答1:


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'
    }
}

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'
        }
    }
}



来源:https://stackoverflow.com/questions/53198890/jenkins-pipeline-ansicolor-console-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!