Last Updated: February 25, 2016
· maxehmookau

Fail a Jenkins Build if Your Ruby Code Sucks

Flog is a tool used to check how awful your Ruby code is. Awful Ruby code should not make it through continuous integration. Add Flog as a step to your build process and make sure tortuous code doesn't make it in to production!

First add

gem 'flog'

to your Gemfile (or Gemspec)

Install the Jenkins text-finder plugin.

Add the following step to your execute shell commands to be run on build:

find lib -name \*.rb | xargs bundle exec flog --score

Then add a post-build step on 'Jenkins Text Finder' which searches for this regex:

^\s*(\d{1,2}\.\d+)(?=.*flog total)

And tick 'succeed if found'

This will fail anything with a flog score of > 100.

(Hat tip to @samknight)

Say Thanks