How to use the ANSIcolor plugin in Jenkins?

Stefan Schroeder picture Stefan Schroeder · Sep 14, 2012 · Viewed 51.4k times · Source

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.

Answer

Mirko Ebert picture Mirko Ebert · Apr 10, 2013

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