【问题标题】:Jenkins pipeline ansicolor console outputJenkins 管道 ansicolor 控制台输出
【发布时间】:2019-04-11 10:32:27
【问题描述】:

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

// 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 时,我希望控制台输出对警告、错误等进行颜色编码。

【问题讨论】:

    标签: jenkins jenkins-plugins jenkins-pipeline


    【解决方案1】:

    AnsiColor 插件“向控制台输出添加了对 ANSI 转义序列(包括颜色)的支持”(https://wiki.jenkins.io/display/JENKINS/AnsiColor+Plugin)。它只是充当一个包装器,以便 Jenkins 控制台输出正确显示颜色,插件本身不会向控制台输出添加 ANSI 转义序列或颜色。

    Ansible 插件 就是一个很好的例子,“可以使用参数 'colorized: true' 启用彩色输出”(https://wiki.jenkins.io/display/JENKINS/Ansible+Plugin#AnsiblePlugin-ColorizedOutput)。 Ansible 插件 的彩色输出需要 AnsiColor 插件,否则 Jenkins 控制台输出无法显示颜色。

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多