在Jenkins管道中,ansiColor Jenkins插件的包装器放在哪里?

在Jenkins管道中,ansiColor Jenkins插件的包装器放在哪里?,jenkins,jenkins-pipeline,ansi-colors,Jenkins,Jenkins Pipeline,Ansi Colors,我不确定如何处理声明性jenkins管道 下面的示例如下: 上面的代码片段到哪里去了 这是我的简单文件: #!groovy pipeline { agent any // Set log rotation, timeout and timestamps in the console options { buildDiscarder(logRotator(numToKeepStr:'10')) timeout(time: 5, unit: 'MINUTES')

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

下面的示例如下:

上面的代码片段到哪里去了

这是我的简单文件:

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

包装纸能绕着舞台走吗?每个阶段都有吗?

我把我的放在每个阶段,就像这样:

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

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

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

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

pipeline {
  agent any 

  options {
    ansiColor('xterm')
  }
...
}

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

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

能够在我给出的答案中配置一次当在Jenkins 2.98和Pipeline 2.5上的脚本管道中使用时,它不起作用。有一个问题需要添加对它的支持:GitHub问题目前仍然存在,但现在它实际上似乎可以正常工作(Jenkins 2.121.1和Pipeline 2.5)。@phani您能解释更多吗?