【问题标题】:Where to put the wrapper for ansiColor Jenkins plugin in Jenkins Pipeline?Jenkins Pipeline 中 ansiColor Jenkins 插件的包装器放在哪里?
【发布时间】:2017-10-15 15:42:56
【问题描述】:

我不确定如何处理声明式 jenkins 管道。

按照此处的示例: https://github.com/jenkinsci/ansicolor-plugin

wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
  sh 'something that outputs ansi colored stuff'
}

上面的sn-p去哪儿了?

这是我的简单 Jenkinsfile:

#!groovy

pipeline {
  agent any

  // Set log rotation, timeout and timestamps in the console
  options {
    buildDiscarder(logRotator(numToKeepStr:'10'))
    timeout(time: 5, unit: 'MINUTES')
  }

  stages {

    stage('Initialize') {
      steps {

        sh '''
          java -version
          node --version
          npm --version
        '''
      }
    }
   }
 }

包装器是否绕过阶段?每个阶段都有吗?

【问题讨论】:

    标签: jenkins jenkins-pipeline ansi-colors


    【解决方案1】:

    能够像这样在选项块中整合配置

    options {
      buildDiscarder(logRotator(numToKeepStr:'10'))
      timeout(time: 5, unit: 'MINUTES')
      ansiColor('xterm')
    }
    

    【讨论】:

    • 这在 Jenkins 2.98 和 Pipeline 2.5 上的脚本化管道中使用时不起作用。
    • GitHub 问题目前仍处于打开状态,但实际上现在似乎可以正常工作(Jenkins 2.121.1 和管道 2.5)。
    【解决方案2】:

    我把我的放在每个阶段都是这样的:

    stage('Initialize') {
      ansiColor('xterm') {
        // do stuff
      }
    }
    

    【讨论】:

    • 在我给出的答案中能够配置一次
    【解决方案3】:

    我把它放在选项部分,申请管道中的所有阶段和步骤

    pipeline {
      agent any 
    
      options {
        ansiColor('xterm')
      }
    ...
    }
    

    【讨论】:

    • @phani 你能解释一下吗?
    【解决方案4】:

    在脚本化的 jenkins 管道中,您可以像这样使用它:

    stage('Pre-Checks') {  
        timeout(time: 3, unit: 'MINUTES') {
            ansiColor('xterm') {
                sh 'python scripts/eod/pre_flight_check.py'
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-25
      • 2012-09-07
      • 2019-04-14
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      相关资源
      最近更新 更多