Coloured Output in Jenkins
Everyone knows that looking at the Jenkins logs to figure out why a build failed can be tedious work.
You’re usually presented with a wall of text which you need to wade through.
Builds that look like this are difficult for members in a cross-functional team to investigate, which ultimately slows everyone down.
Fortunately there are number of improvements we can make for both Ruby and other languages.
The first step is to install the Jenkins AnsiColor plugin.
Once you’ve done that, make sure the xterm colours are present in the Jenkins configuration screen.
You have to enable colours for each job that you want to see colours for.
You should now be running with basic colour output. Great.
To get RSpec colours working in Jenkins you have to specify the following in the RSpec configuration block:
This is because the Jenkins shell is a pseudo TTY.
Ruby colours (colorize gem)
If you want to get some really sweet colour action going on like this:
You have to do a couple of things.
First, add the
colorize gem to your Gemfile.
Next, you need to monkey-patch the Ruby
IO class (yeah, I know). There’s some discussion on this
Now you just need to use
colorize in your Ruby code…
Picking the colours to use
Here’s a really handy tip if you want to experiment with which colours work best for you.
Create a Jenkins job with the following:
Now run it…et voila!
Finally, if you’re feeling really helpful you can provide your team members with a glossary of what each colour means in your build: