The more I use CI(Continuous Integration), the more I like it. 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 your software development process.
If your team is not using CI, that’s no excuse for you. I’m here to help! You can easily set up, on your local machine, a VM(Virtual Machine) and run Jenkins inside. Then you can start using it. My purpose is not to try and 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 a reference to get everything up and running. Let’s use this post to give just a little insight into what’s happening there.
If you follow the (few) instructions, by the end of the process you’ll have a server running Jenkins. Cool uh? For a small effort you can start “playing” around. This setup is composed of 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 your 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 ones 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 that 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.