Skip to content


Rails jenkins

February 06, 2017

Start by setting up a container/VM with ubuntu 12 LTS

sudo apt-get install software-properties-common python-software-properties

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java8-installer

sudo apt-get install oracle-java8-set-default echo JAVA_HOME=“/usr/lib/jvm/java-8-oracle”  | sudo tee /etc/environment source /etc/environment wget -q -O - | sudo apt-key add - echo deb binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list sudo apt-get update

sudo apt-get install jenkins

sudo apt-get install git

sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6 libreadline6-dev zlib1g zlib1g-dev imagemagick libmagickcore-dev libmagickwand-dev sqlite3 libsqlite3-dev libxml2-dev unzip sudo apt-get install redis-server postgresql-9.1 libpq-dev postgresql-contrib

wget -qO-\_6.x | sudo bash - sudo apt-get install -y nodejs npm install -g phantomjs-prebuilt

sudo su - jenkins

This step with rbenv maybe unnecessary since the jenkins plugins does the same thing

git clone ~/.rbenv echo ‘export PATH=“$HOME/.rbenv/bin:$PATH”’ >> ~/.bashrc echo ‘eval ”$(rbenv init -)“’ >> ~/.bashrc exec $SHELL

git clone ~/.rbenv/plugins/ruby-build

#install ruby version if not using rbenv plugin rbenv install 2.3.1

#Edit this to match github git config —global “John Doe” git config —global [email protected]

ssh-keygen and upload to github as required.

On the Jenkins UI install plugins

  • git
  • github
  • rbenv
  • Rake
  • envInjector plugin to populate .envrc equivalent

follow these guides here for project setup -RVM specific RBENV

Postgres related

Configure postgres pg_hba.conf to match your database.yml. Contrary to popular belief you dont need to copy any database config

Using 9.5+ version

sudo sh -c ‘echo “deb `lsb_release -cs`-pgdg main” >> /etc/apt/sources.list.d/pgdg.list’

wget -q -O - | sudo apt-key add -

sudo apt-get update 

sudo apt-get install postgresql postgresql-contrib

Despite all the guides, much of Rails on Jenkins is trial and error. Setting up a new project is relatively easy as per the linked guides but YMMV.

In addition I have had to edit code to make it Jenkins friendly and enabling JUnit reports in rails via Gems is very useful.

Note that installing a single instance of postgres on the Jenkins master is alright for small local developments but not useful for large parallel builds as you are essentially on one DB. I hope this is good enough for anyone to get started and help improve upon the setup.

Possible Further improvements: Use containers for postgres, build vm Use EC2 or Azure Vm plugins use Jenkins Pipeline

You are welcome to connect with me. Abhishek Dujari
This is my archived blog where you will find content about early days of Cloud Computing, Cybersecurity, Development and Sysadmin.