Adventures with Jenkins CI on Mac OSX & Linux

Abstract:

In an agile software development, Continuous integration became integral part of agile process and agile team won’t be considered as effective without effective and visible continuous integration(CI). Continuous integration server runs automated test after each time developers check-in into the source code repository and notify team in case build failed. Continuous integration won’t allow developers to build legacy code which in turn increase technical debt. Continuous integration helps a lot in quality of the product.

Continuous Integration
Continuous Integration

Jenkins:

Jenkins is a most popular continuous integration tool. Jenkins has been developed and maintained by Kohsuke Kawaguchi who is currently working at cloudbees. Jenkins became so powerful CI server due to it’s nice looking web interface and it’s hundred’s of plugins.

In this short tutorial, we will learn how to install jenkins on your computer.

Jenkins On Mac OSX:

  • Using Jenkins-OSX installer package

Simplest way of installing Jenkins on Mac OSX is to download 0sx-installer package () from Jenkins websiteand following the instructions. You can find this package in your ‘Downloads’ directory called ‘ jenkins-{version}.pkg’. Now current version is ‘jenkins-1.478.pkg’ .

Double click on the package, you will get installer window and follow the steps which includes Introduction, License, Destination Select (location of Jenkins), Installtion Type, Installtion and Summary. Add jenkins package in your Applications and you are done! So simple isn’t it?

Remember, this package is broken and you may get get a 404 ‘not found’ message from the winstone-server that is bundled. If you dig in your syslog, you’ll find a reviling stack trace that indicates that a file can’t be found.
Solution for this issue is to create dedicated users to run jenkins. Run following commands from your terminal

Then update at /Library/LaunchDaemons/org.jenkins-ci.plist file to use ‘jenkins’ user

After doing that, the Home folder of jenkins, /Users/Shared/Jenkins/Home needs a new owner.

Finally, unload and reload jenkins service

If you need to access your git repos using a public ssh key, you can generate one now by logging in as the jenkins user and running ssh-keygen

Now, open your web browser and type ‘ http://localhost:8080/’ and see jenkins installed in your Mac.

  • Downloading War file (standalone)

You can also install jenkins as a standalone application by downloading jenkins.war file from jenkinswebsite. On right hand side of the website, you will find ‘Download Jenkins’ and Java Web Archive (.war). Download the latest version. It will be downloaded in your ‘Downloads’ directory. Now open terminal and run these commands (in this case ‘Shashi-MacBook-Pro:Downloads user$’ is my home directory.

Now, open your web browser and type ‘ http://localhost:8080/’ and see jenkins installed in your Mac.

  • Using Mac Brew package to install Jenkins  (Prefred )

I pearsonally, prefer this method of installing Jenkins on Mac as It will many problems that you may face if you install Jenkins using any of the above method.

You can’t clone private github repositories and you can’t use your own private key if you install Jenkins with above method. So I would definately recommend this method in order to instal Jenkins o Mac. Pre-requisite is You must have homebrew installed on your Mac.

I assume that, you got homebrew installed on local Mac. Now try running these commands

Or start it manually:

==> Summary
/usr/local/Cellar/jenkins/1.477: 3 files, 47M, built in 18 seconds

Now run following commands in order to create Jenkins user and deamon

Mac OS uses launchd to control daemons and agents. It’s pretty easy to create a launch daemon. Create the file

with the following content, based on the plist from the homebrew jenkins formula. You may need to update the version number in the ProgramArguments.

Insert following containt into this file. You may need to change the version of jenkins accordingly.

Now you need to load the daemon using

Or You can just rebot your Mac.

Create an ssh key

Like I said, I wanted jenkins to have its own ssh identity. This is fairly easy:

You will see output like this

The new key is in /var/jenkins/.ssh/id_rsa.pub and can be copied to github, or wherever you have your source code.

Jenkins on Ubuntu

Setting up Jenkins on ubuntu is fairly simple. You need to run following commands in order to achieve this

To update Jenkins run

Jenkins on CentOS

CentOS has yum package for Jenkins. Just run as a root user.

Now, open your web browser and type ‘ http://ipaddress:8080/’ and see jenkins installed.

Jenkins Homepage

Enjoy this installed interface of Jenkins. In the next tutorial, we will see how to create job in Jenkins.

Happy CI !!