The OP asked explicitly about using AnsiColor Jenkins Plugin on Windows, so here is my answer:
cmd.exe is not a terminal emulator
As @ocodo wrote, cmd.exe
(which is triggered by Jenkins) is not a terminal emulator, so it won't support ANSI output from batch commands by default.
So this is just unsupported on Windows.
These tests were unsuccessful in Jenkins using Windows Batch build step:
echo \e[33m hello \e[0m
echo \033[33m hello \033[0m
echo \x1b[33m hello \x1b[0m
echo \27[33m hello \27[0m
echo \[33m hello \[0m
echo ←[33m hello ←[0m
Last line: To inject an ESC character in a Firefox testbox form, press alt+27, which is also the escape sequence in most editors. more info here: http://www.robvanderwoude.com/ansi.php#AnsiColor and https://groups.google.com/forum/#!topic/jenkinsci-users/0OcjlZQfqrk
A solution: Use Python print for text coloring
The build jobs which use Python for console output had no problem with AnsiColor, so if Python is available in your environment where the console output is generated by a script, you can inject ANSI codes from there. Here's how I worked around it to make it colorful.
- Create a helper script in
util/ansiGreen.py
like so:
#!/usr/bin/env python
print("\033[32m");
- Register as env var at the level of your global build configuration:
set ansiGreen=python %cdRootPath%util\ansiGreen.py
call make-some-tests.bat
if %errorlevel% gtr 0 (
%ansiRed%
echo [ERROR] You screwed up trunk!
%ansiOff%
)
As you can see, %ansiOff%
is also required, to end with coloring (Its simply "\033[0m"
printed through python). Else everything after %ansiRed%
will be in red.
This script is run on a Jenkins slave. To set and get an environment directly within Jenkins batch build step is another challenge.
It's a bit ugly but after a lot of research it seems to be the best workaround to enable AnsiColor to be returned to a Windows Jenkins master from a Windows Jenkins slave.
wrap
thesh
in an extra class according to github.com/dblock/jenkins-ansicolor-plugin – MarkHu