Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the ANSIcolor plugin in Jenkins?

I have installed the ANSI-color plugin for Jenkins. In the Jobs I have activated that plugin with the default profile 'xterm'.

I cannot figure out how to colorize the output of the Console Log when printing to the log from the batch files (Windows-platform).

The documentation on

https://wiki.jenkins-ci.org/display/JENKINS/AnsiColor+Plugin

is not helpful. There are no examples how to actually print in color.

I tried several different echo/print commands, but I cannot get colors to work.

Any hint appreciated.

like image 305
Stefan Schroeder Avatar asked Sep 14 '12 16:09

Stefan Schroeder


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.

How do I read Jenkins console logs?

In order to read the console output in Jenkins, All you need to do is copy and paste the code as a stage in your pipeline script. After the build is run, a file named buildConsolelog. txt will be stored in the home directory of your project.


1 Answers

The ANSI-color plug in transforms your console output to HTML. If your output contains ansi escape sequences, then it converts these special char sequences into (colored) HTML. You can only configure the mapping via 'ANSI color map'.

Example:
\x1b[31m is transformes html color red

It looks that your program does't use Escape sequences. But if you wrote your own software or script, you can use these Escape sequences.

1st Example BASH:

echo -e "\033[31mRed\033[0m" 

2nd Example BASH:

printf "\033[31mRed\033[0m" 

If you need it, you have to add a newline sequence to printf:

printf "\033[31mRed\033[0m\n" 

More to Escape sequences:
English: http://en.wikipedia.org/wiki/ANSI_escape_code
Deutsch: http://de.wikipedia.org/wiki/Escape-Sequenz

like image 52
Mirko Ebert Avatar answered Sep 21 '22 12:09

Mirko Ebert