Skip to content

Instantly share code, notes, and snippets.

Created May 29, 2012 14:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save iafonov/2828887 to your computer and use it in GitHub Desktop.
Smart cucumber test runner for Jenkins CI
require 'fileutils'
BUILDS_PATH = '/var/lib/jenkins/jobs/secret_project/builds'
# list of build directories
builds = Dir.entries(BUILDS_PATH).select{|dir| dir =~ /^\d{1,4}$/}.map{|dir| dir.to_i}.sort
stats = builds.inject({}) do |stats, build_number|
`grep -r "cucumber" #{File.join(BUILDS_PATH, build_number.to_s)}`.each do |line|
line.match /workspace\/(.*?)\:(\d*).*Scenario: (.*)/
next if $1.nil?
if stats.has_key? $1
stats[$1][:count] += 1 # failures count
stats[$1][:weight] += (build_number.to_f / builds.size) # failures 'weight'
stats[$1] = {:count => 0, :feature => $1, :line => $2, :scenario => $3, :weight => 0}
top_failing = stats.sort_by{|k, v| v[:weight]}.
select{|line| FileTest.exists?(line[1][:feature]) }.
reverse.first(5).map{|line| line[1]}
exec "bundle exec cucumber --tags ~@wip -r features/ #{{|line| line[:feature]}.join(" ")}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment