How To Install Jenkins And Set Up Jenkins CI For Rails Projects

Travis CI is a great solution for OpenSource project. However, what if you want to setup an internal CI server for private projects? Jenkins CI is the choice.

In this post, I’ll guide you through installing and configuring Jenkins CI on a VPS (EC2 instance in this post)

OS Assumption

Assume that you are running an EC2 instance with a Ubuntu system as below:

Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-40-virtual x86_64) 

If you don’t yet have a VPS set up, there is an Amazon free tier that is recommended.

Install Rails Environment

Because you’ll be using this Jenkins CI server for Rails projects, install the following Ruby/Rails libs and tools:

– Install RVM and Ruby

We need to have git core and curl for RVM installation, so install them like so:

sudo apt-get install build-essential git-core sudo apt-get install curl 

And install RVM with ruby as user jenkins:

#remember to switch to user `jenkins` first sudo su jenkins  curl -L https://get.rvm.io | bash -s stable --ruby sudo apt-get install libmysqlclient-dev ruby-dev 
– Install Possible Databases
MySQL
sudo apt-get install mysql-client mysql-server libmysql-ruby libmysqlclient-dev 
Postgres
sudo aptitude install libpq-dev sudo apt-get install postgresql sudo apt-get install postgresql-client 

If you had a problem with UTF-8 take a look at http://wiki.gentoo.org/wiki/PostgreSQL

MongoDB
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list sudo apt-get update sudo apt-get install mongodb-10gen 

Now Install Jenkins

Installation:

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 aptitude update sudo aptitude install jenkins 

Uninstalling Jenkins is easy too, just:

sudo apt-get remove jenkins 

FYI – There is also a detailed guide for installing Jenkins on Ubuntu.

Run Jenkins on Port 80

By default, Jenkins runs on port 8080, so you’ll need to reverse proxy port 80 to port 8080 for Jenkins. This will make the CI server public to the world.

To install nginx and set this up, open up a terminal and type in:

sudo apt-get install nginx sudo /etc/init.d/nginx start 

Open up the config file in vim, and update it.

sudo vim /etc/nginx/nginx.conf 
http {          # ...Omitted Parts…          include /etc/nginx/conf.d/*.conf;    # This line not modified.         include /etc/nginx/sites-enabled/*;  # This line not modified.          ##         # Reverse proxy port 80 to port 8080 for Jenkins         ##         server {                 listen 80 default;                 server_name your.domain.com;                 location /{                         proxy_pass http://127.0.0.1:8080;                 }         } }  

Notice: Jenkins shows build histories and other information. Tto keep the whole CI server private, you’d better use this guide to add basic auth for your Jenkins CI. It is strongly recommended.

Install valuable plugins for Jenkins

After all of the above installations are done, you are able to visit your Jenkins CI server using your domain. Now it’s time to install the following plugins from the JenkinsPlugin > Manager section:

For more plugins, check out the Jenkins Plugins Document.

References & Resources

https://wiki.jenkins-ci.org/display/JENKINS/Configuring+a+Rails+build
http://watirmelon.com/2011/08/29/running-your-watir-webdriver-tests-in-the-cloud-for-free/

Ready to build an industry-changing product?

Let’s talk about your project today >>