I was recently setting up a Jenkins Server, here is a simple tutorial on how to do it.
The agenda
- Jenkins Build Server for building a gradle project
- Github Authentication
- Run Builds from Github private repository
- Build Pull requests
Step 0:
Get a Ubuntu 12.04 Server with at-least 1 GB RAM and a good processor.
If you are building this on EC2 a M1 Small Instance will suffice.
Step 1: Setup Ubuntu
- Install openjdk on the server by typing
sudo apt-get install openjdk-7-jdkon the terminal. - Install
gitusingsudo apt-get install git
Step 2: Install jenkins
Install jenkins by following the tutorial on jenkins-ci.org
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -- Add the following line to
/etc/apt/sources.listdeb http://pkg.jenkins-ci.org/debian binary/
sudo apt-get updatesudo apt-get install jenkins
Step 3: Start Jenkins
- Start the Jenkins server by typing
sudo service jenkins start, - Make sure its running by typing
sudo service jenkins statusto get a result likeJenkins Continuous Integration Server is running with the pid xxxx. - And finally visit the
http://<sever-ip>:8000/to get a page like

Step 4 : Install plugins
Here is a list of plugins and version that I have installed at the time of writing this tutorial
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
These plugins can be installed from Manage Plugins page

Step 5 : Configure Jenkins
- Open the configuration page

- Set jdk installation to
/usr/lib/jvm/java-7-openjdk-amd64

- Assuming you have installed git via the package manager, you can leave the configuration as it is.

- Assuming the gradle plugin has been installed, Configure the gradle installation

- Set the url of the jenkins server

- Configure the git installation of the git client

- Setup Email Notifications if you need it

- Setup the github hook and the pull request builder, Refer Step 8 for the credentials of the pull request builder.

The admin list is a list of admin usernames in github separated by white space.
Step 6: Setup Security with Github Login
- To use github login, Register an application with github. Make sure the callback url is
http://<server-ip>/securityRealm/finishLogin

- Once the application is registered copy the
cliend Idandclient Credentials

- And add them to the oauth plugin

- Set the admin github users and organisations

Step 7: Setup ssh key for jenkins
- Ssh into the server and swtich user to
jenkinsusing the commandsudo su jenkins - Navigate to the home directory and create a directory called
.sshusingmkdir .ssh - use the command
ssh-keygen -t rsato generate a new ssh key , do not set any password for the key - restart the jenkins server using
sudo service jenkins restart
Step 8: Builds user
- Create a new builds user in github
- Upload the public key generated in the previous step to github
- Grant permission for the builds user to access your private repository
- Enter the credentials of the build user for the pull request builder in Step 5.
- Refer help.github.com for more information on this step
Step 9: Create a new Job
Create a new job
Setup the vcs for the job as git, Enter the repository url from which to clone, like
git@github.com:username/example.git- Set the name of the repository ass
origin

- Specify the branch to build like
origin/master - Set the repository browser as githubweb and specify the url of the Github project like
http://github.com/user/project - Check the options
Build when a change is pushed to GitHubandGithub pull requests builder - Add a build step
Invoke a gradle script - Add a new build post build action for sending an email.
Step 10:
Enjoy the power of Continuous Integration on you Github project with gradle builds.
