Continuous Integration in Rails with Jenkins

Rajeswari K

1 min read

Jenkins is an open-source Continuous Integration tool and it is easy to integrate in Rails project. A CI package will run automated tests on a server on a set(daily) or evented(whenever commits are made) interval. Now we shall see how to setup a build and test rails 3 applications.

1. Install jenkins
In Ubuntu

    [source language=”ruby”]
    wget -q -O – http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add –
    sudo sh -c ‘echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list’
    sudo apt-get install jenkins
    [/source]

2. Start Jenkins CI

    [source language=”ruby”]
    sudo /etc/init.d/jenkins start
    [/source]

This will start the server in http://localhost:8080 port.

3. Create a job
From the Dashboard of Jenkins

  • Select Create new jobs
  • Provide Job name with suitable name
  • Select Build a free-style software project option button and OK

4. Configure project
After created the new job click on the job name and select Configure Project. The window will look like the follwing. In that,

  1. Select Source Code Management as Git and provide the corresponding Repository URL.
  2. Select Build Triggers -> Build when a change is pushed to GitHub so jenkins triggers when we push into Github.
  3. Under Build select Add Build step -> Execute shell (It runs a shell script for building the project. The script will be run with the workspace as the current directory).
    • [source language=”ruby”]
      #!/bin/bash -x
      source ~/.bashrc
      export GEM_PATH=/home/rajeswari/.rvm/gems/ruby-1.9.2-p290
      bundle install
      rvm use –default&& rvm-shell -c “RAILS_ENV=test &&rake spec cucumber”;
      [/source]
  4. Select the needed Post build actions that will generate reports after every build.
  5. Click Apply then Save

5. Build job
Select Build now from the left side menu. It will run the shell script we provided and generate the selected reports.
6. Enable Brakeman reports
Brakeman is a static analysis tool which checks Rails applications for security vulnerabilities. To enable this we need to install brakeman plugin from Jenkins dashboard. For that select jenkins -> Manage plugins. Under Available tab check brakeman plugin and restart the server. Add

    [source language=”ruby”]brakeman -o brakeman-output.tabs[/source]

in Execute shell command. The trend graph will be shown as below.

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *