Skip to end of metadata
Go to start of metadata


This information is outdated. Please lookup some tutorials on Google of you need help...

Guide to configuring a Rails project in Jenkins

I had some problems getting Jenkins to play along with the "Jenkins ruby metrics plugin", so I wrote this guide to document my setup. Hope it helps someone else out.

Based loosely on:

Notice that Saikuro reports aren't currently working.


Jenkins needs to have the following plugins installed: "Jenkins Ruby Plugin", "Jenkins ruby metrics plugin". Also, the build server needs Ruby and rubygems.

The build process will take care of installing any gems, as long as they are in "config/environment.rb".


edit Rakefile and add the following:

require 'rubygems'
# Install:
#  sudo gem install ci_reporter
gem 'ci_reporter'
require 'ci/reporter/rake/test_unit' # use this if you're using Test::Unit

Install the rcov-plugin, by running:

./script/plugin install

Add a dummy test case, to please rcov. Put the following in "test/unit/dummy_test.rb", "test/functional/dummy_test.rb" and "test/integration/dummy_test.rb":

# This is because rcov chokes, when there are no test cases found.
require 'test_helper'

class DummyTest < ActiveSupport::TestCase
  def test_truth
    assert true

(Once you add real test cases to the project, you can remove these again)

Unless you require a MySql database, you can set the test database to sqlite. Otherwise, you'll have to create a test database somewhere, and put credentials in "database.yml". Remember to add sqlite as a dependency to "config/environment.rb", if you use it.

Since Rake can't always install missing gems through the "rake gems:install" task, we'll have to put the install the following plugin:

./script/plugin install

SVN add new files and commit the changes.


Select "New Job"

Check option "Build a free-style software project" and enter a name. The name should be CamelCaseWithoutSpaces

Under "Source Code Management", select "SVN"


Repository URL: http://blah/project/trunk
Local module directory (optional): trunk

Under "Build Triggers", select "Poll SCM"


# Poll every 5 minutes
*/5 * * * *

Select "Add Build Step" -> "Execute shell"


# enter application root
cd trunk
# install missing gems
# set env vars
export GEM_PATH=/usr/local/lib/ruby/gems/1.8/gems
export CI_REPORTS=results
export RAILS_ENV=test
# Prepare for rcov
[ -d "coverage" ] && rm -rf coverage
mkdir coverage
# invoke rake
rake db:create db:migrate ci:setup:testunit test:test:rcov --trace RCOV_PARAMS="-I/usr/local/lib/ruby/gems/1.8/gems --aggregate coverage/"

(Note that if your GEM_PATH differs, you'll have to adjust it in the above)

If you'd prefer to only make coverage reports for unit tests, you can replace "test:test:rcov" with "test:units:rcov test"

Under "Post-build Actions", select "Publish JUnit test result report", "Publish Rcov report" and "Publish Rails stats report"

In "Test report XMLs", enter "trunk/results/*.xml"

In "Rcov report directory", enter "coverage/units"

Click "Build Now" to test the configuration.

  • No labels