A small help to get you into Continuous Integration

The more I use CI(Continuous Integration), the more I like. Sure it can be a “pain” in the beginning, but the gains are enormous. You can easily start getting results in a short period of time and improve you software development process.

If your team is not using CI, that’s no excuse for you. I’m here to help! You can easily setup, on your local machine, a VM(Virtual Machine) and run Jenkins inside. Then you can start using it. My purpose is not trying to convince anyone into using CI, but instead make it easier to start using.

For this purpose, I’ll give you a hand. Check my repository on GitHub: vagrant_jenkins. The README is self explanatory and you can use it as reference to get everything up and running. Let’s use this post to give just a little insight on what’s happening there.

If you follow the (few) instructions, by the end of process you’ll have a server running Jenkins. Cool uh? For a small effort you can start “playing” around. This set up is composed by two files: the Vagrant and the bootstrap.sh files. The Vagrant file will be used by vagrant to configure the VM itself and the  bootstrap.sh will be used to provision you server (basically install and configure everything you need).

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.network "forwarded_port", guest: 8080, host:8080

  config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", "1024"]
  end
end

You can see here that Vagrant will download a “box”, corresponding to Ubuntu Precise Pangolin and use it as an OS. We also tell the VM that it should provision using our file, to forward ports so we can access Jenkins on our host and the amount of memory we want. Next comes bootstrap.sh.


#!/usr/bin/env bash


echo "Add Jenkins key"
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'

echo "Add PosgreSQL key"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sh -c 'echo deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main > /etc/apt/sources.list.d/pgdg.list'

echo "Update repos"
apt-get update

echo "Install OpenJDK and Jenkins"
apt-get install -y openjdk-7-jdk jenkins git

echo "Install other packages"
apt-get install -y python-pip python-virtualenv libpq-dev python-dev

echo "Install Postgres"
apt-get install -y postgresql-9.3 postgresql-contrib-9.3

This one is even simpler. We just fetching and installing all the packages we need. The required one’s to run Jenkins are Java and Jenkins itself. The other’s you see there are some I normally use. If you don’t need them, just remove the corresponding code.

Please be patient the first time you run the instructions. There’s a lot being done, sot it might take a while.

By the end of it, you’ll have a basic setup which you can then use to manage your builds. Start using it, share with your colleagues, managers, supervisors, etc and you’ll see they will be interested in no time.
 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s