Jenkins管道Ansicolor控制台输出 [英] Jenkins pipeline ansicolor console output

查看:703
本文介绍了Jenkins管道Ansicolor控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以使用AnsiColor插件在控制台输出中显示颜色.我在下面测试了一个基本示例:

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

但是,这个例子太基础了,本质上是硬编码的.是否可以利用AnsiColor对整个控制台输出进行颜色编码?例如,当我为.NET项目执行Nuget和MSBuild时,我希望控制台输出对警告,错误等进行颜色编码.

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.

推荐答案

AnsiColor插件在控制台输出中添加了对ANSI转义序列(包括颜色)的支持"(

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.

一个很好的例子是 Ansible插件,其可以使用参数'colorized:true'启用彩色输出"(

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.

没有 AnsiColor插件包装器的彩色输出:

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

使用 AnsiColor插件包装器进行彩色输出:

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

这篇关于Jenkins管道Ansicolor控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆