提问者:小点点

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


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

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

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

上面的片段去哪里了?

这是我的简单 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
        '''
      }
    }
   }
 }

包装器会绕过阶段吗?它会绕过每个阶段吗?


共3个答案

匿名用户

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

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

匿名用户

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

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

匿名用户

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

pipeline {
  agent any 

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