Reputation: 24297
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?
Upvotes: 25
Views: 21524
Reputation: 2443
In a scripted jenkins pipeline, you can use it like this:
stage('Pre-Checks') {
timeout(time: 3, unit: 'MINUTES') {
ansiColor('xterm') {
sh 'python scripts/eod/pre_flight_check.py'
}
}
}
Upvotes: 5
Reputation: 1083
I put this in options section, apply for all stages and steps in pipeline
pipeline {
agent any
options {
ansiColor('xterm')
}
...
}
Upvotes: 9
Reputation: 24297
Able to consolidate config in the options block like so
options {
buildDiscarder(logRotator(numToKeepStr:'10'))
timeout(time: 5, unit: 'MINUTES')
ansiColor('xterm')
}
Upvotes: 40
Reputation: 940
I put mine in each stage like this:
stage('Initialize') {
ansiColor('xterm') {
// do stuff
}
}
Upvotes: 10