It’s now easier than ever to try out new tools and applications. Case in point: this week I’ve been working on a new build and deploy process for a customer. They are moving to a new workflow with continuous integration. So, I wanted to try out some specific features of Jenkins to see if these could solve the problem. If I was going to set it up manually what would I have had to do? Well first request a VM or create my own locally. Then I’d have picked and installed a Linux distro, configured SSH, logged in. Then I’d have read the documentation for Jenkins, followed an install guide. Maybe manually forwarded a port so that other VMs in my environment could reach it.

So what’s the easier way? We can use Vagrant to provision a virtual machine locally and we can have it trigger a config management tool to install Jenkins. Vagrant has good hooks into Puppet, Chef, Salt and Ansible. And there’s already a wealth of Cookbooks, formulas etc. to install things like Jenkins in a proper way.

For this example I’ve chosen Chef. Here’s what I actually did. I’ll even include the steps that you only need to do once:

1. Install Virtual Box (or VMWare Fusion if you like)

2. Install Vagrant.

3. Install the ChefDK. We need this because we want Chef’s dependency resolution tool Berkshelf. This will allow us to just specify the Jenkins cookbook and let Berkshelf find any cookbooks on which it depends.

4. Install some vagrant plugins:
# First the Berkshelf plugin
vagrant plugin install vagrant-berkshelf
# Then the vagrant-cachier plugin. This one's optional but it'll save you a lot of time and bandwidth!
vagrant plugin install vagrant-cachier

5. Now create a new folder and VagrantFile
mkdir vagrant-jenkins
cd vagrant-jenkins
vagrant init ubuntu/trusty64
# Note you want an OS that the cookbook supports. However most will work with recent versions of Ubuntu.

7. So we want to use Chef to setup Jenkins for us. So we need to create a Berksfile so that Berkshelf knows what cookbooks we want to download.
touch Berksfile

And open it in your favourite editor. Here’s what we need to add:
source ''
cookbook "jenkins"

Pretty simple right! You could probably even have guessed the cookbook existed and not bothered to look it up. But just in case here it is.

8. Now we need to tell Vagrant to use the Chef provisioner and to run a recipe from this cookbook. Open up the Vagrantfile and add the following before the end of the Vagrant configure block.
config.berkshelf.enabled = true
config.vm.provision :chef_solo do |chef|
chef.add_recipe "jenkins::master"

This tells Vagrant to use Berkshelf to resolve dependent cookbooks. It sets Chef solo as the provisioner and selects the Jenkins master recipe from the cookbook.

9. Expose the Jenkins port from the VM. Just to make life easier we’ll expose the jenkins port so that we can access it at http://localhost:8080. If you are using Virtual Box with the default network config and want to reach it from other VMs you’ll find it at Just add the following to the Vagrantfile before the last end. "forwarded_port", guest: 8080, host: 8080

10. Finally we can run:

vagrant up

Now we just wait a few minutes or even less if you already have the vagrant box cached. When vagrant exits you should see lots of green text with the output from Chef solo and you should be able to access your new Jenkins instance at http://localhost:8080. Note that you could now use this method to bring up a test instance of nearly any software that there is already a cookbook for and you can start at step 5 in the future. Check out some popular ones on the chef supermarket.

< Back