github with jenkins

Posted on Monday, January 27, 2014



This guide will go over installing the git plugin for Jenkins. It assumes you have Jenkins already installed and running (Very basic setup).  If you have not done that yet I wrote a how to guide at http://www.whiteboardcoder.com/2014/01/install-jenkins-ubuntu.html


As a side note there is a github plugin to Jenkins https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin [1]  But I will not be going over that, rather I will just use the basic git plug-in to talk to github



Install git via apt-git


First git needs to be installed on the Ubuntu machine


> sudo apt-get install git



Install plug in

Open your Jenkins install in a web browser.  Mine happens to be located at http://192.168.0.7:8080/

After you login click on Manage Jenkins





Click on Manage Plugins






Click on the Available Tab






In the filter enter "git plugin"
Then select "Git Plugin" and finally click on "Install without restart"






Plug-in installation starts





After the plug-in is successfully installed click on "Go back to the top page"





SSH keys


Create the ssh keys in the Jenkins home directory.  In my set up the Jenkins home directory is at /var/lib/jenkins

Switch over to the Jenkins user and create its ssh keys


> sudo su jenkins
> cd
> ssh-keygen -t rsa -b 2048


Copy the id_rsa.pub key to obtain it you could run the following command



> cat .ssh/id_rsa.pub



Copy this somewhere in order to upload it to github




Upload ssh keys to github


Login to github. 
From your profile click on SSH Keys




Click on Add SSH key




Give it a Title, Paste the id_rsa.pub text into the key and click Add Key

 



Open github repository


Click on New Job






Name it Test
Select "Build a free-style software project"
Click OK







At this point you need to get the url of a remote git repository to clone from.

For this example I chose jquery https://github.com/jquery/jquery [2]

The URL to clone is located here on their github page, copy it.





In this case its
git@github.com:jquery/jquery.git

Replace the : with a / to give you and prefix it with ssh://

ssh://git@github.com/jquery/jquery.git



Now back to the Jenkins job page

Select "Git" then enter the github remote repository

ssh://git@github.com/jquery/jquery.git







Click Save







Click Build now







The Build was successful



This is a very simple deploy, all it does is download from the github repository.


This same technique works with closed github projects your github user has access to.



References
[1]        Jenkins github plugin
                Accessed 01/2014
[2]        jquery github site
            https://github.com/jquery/jquery
                Accessed 01/2014


No comments:

Post a Comment