Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 938
Eric Francis Avatar asked May 16 '17 13:05

Eric Francis


People also ask

What is AnsiColor in Jenkins?

Jenkins ANSI Color PluginThis plugin adds support for standard ANSI escape sequences, including color, to Console Output. This plugin is available here and has a page on the Jenkins Wiki.

Which Jenkins plugin is used to create Jenkins pipeline?

Jenkins 1.580. 1 or later (Jenkins 2.0 is recommended) The core Pipeline plugin.

How do I add ansicolor to a Jenkins pipeline?

This plugin is available here and has a page on the Jenkins Wiki. There are 2 ways to explicitly enable ansicolor functionality in a pipeline: as a build wrapper - the cleanest and most preferable one or as a pipeline step - good for quick checks when you only need part of the output colored.

What is the ANSI color plugin for Jenkins?

Jenkins ANSI Color Plugin. This plugin adds support for standard ANSI escape sequences, including color, to Console Output. This plugin is available here and has a page on the Jenkins Wiki.

What are some examples of plugins with Jenkins pipeline support?

Few examples of plugins which have Jenkins Pipeline support examples on wiki pages: Slack Plugin SonarQube Scanner Stash Build Notifier Easy way #2 We can use snippet generatorfrom Jenkins. Hard way

Are there any plugins that integrate with pipeline-compatible steps?

The following plugin provides functionality available through Pipeline-compatible steps. Read more about how to integrate steps into your Pipeline in the Steps section of the Pipeline Syntax page. For a list of other such plugins, see the Pipeline Steps Reference page.


2 Answers

Able to consolidate config in the options block like so

options {   buildDiscarder(logRotator(numToKeepStr:'10'))   timeout(time: 5, unit: 'MINUTES')   ansiColor('xterm') } 
like image 92
Eric Francis Avatar answered Sep 28 '22 16:09

Eric Francis


I put mine in each stage like this:

stage('Initialize') {   ansiColor('xterm') {     // do stuff   } } 
like image 31
Jacob Avatar answered Sep 28 '22 15:09

Jacob