Where to put the wrapper for ansiColor Jenkins plugin in Jenkins Pipeline?

Eric Francis picture Eric Francis · May 16, 2017 · Viewed 16.8k times · Source

I'm unsure of what to do with declarative jenkins pipeline.

Following the example here: https://github.com/jenkinsci/ansicolor-plugin

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

Where does the above snippet go?

Here is my simple 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
        '''
      }
    }
   }
 }

Does the wrapper go around stages? Does it go around each stage?

Answer

Eric Francis picture Eric Francis · May 16, 2017

Able to consolidate config in the options block like so

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