This post introduces you the steps to setup Jenkins (Continuous Integration Server) with Git repository.
Continues Integration is a must for every Perficient GDC project. Setting up a Jenkins server and connect it with Perficient GDC Git repository is the first step for setting up a complete CI environment. After helping more than three people about how to set it up, I decided to write it down for future reference.
I got a fresh Ubuntu 14.04 VM server from IT service team, then I installed a Tomcat7 on it. After downloading the latest Jenkins.war file from official Jenkins site, I deployed Jenkins through tomcat admin page without any problem. You need to have a Jenkins instance up and running to continue with the following steps:
Step 1. Install Git
Shell> sudo apt-get install git
Step 2. Install the Git Plugin in Jenkins
Go to “Manage Jenkins>>Manage Plugins”, open the “Available” tab and search for “Git plugin”, click on install button wait until the installation is done.
Step 3. Create ssh key pair
Go to the “Manage Jenkins>>System Info” page (http://your-jenkins-server/jenkins/systemInfo).
Search for “user.home”, you have the following information
Keep a note on the value of “user.home” and “user.name”, it indicates under which account your Jenkins server is deployed.
Now you get everything you need for generating the ssh keypairs.
#Create a .ssh folder to hold your ssh keys
Shell> mkdir /usr/share/tomcat7/.ssh
#Generate ssh key pairs
# The –f option is to specify which file to save the key
Shell> ssh-keygen -t dsa -f /usr/share/tomcat7/.ssh/id_dsa
Just leave the pass phrase empty, you will get the following output:
You will find two new files are generated:
Step 4. Get the content of ~/.ssh/id_dsa.pub file
Enter the following command
#please replace the user home with your won value
Shell> vi /usr/share/tomcat7/.ssh/id_dsa.pub
You will get something like this: (the following key string is not complete, so don’t even think of using it to hack my account : ) )
Step 5. Setup the ssh key in Git
Login to Perficient GDC Git and then go to “profile settings” page, click on the “SSH Keys” link on the top navigation bar, click “Add SSH Key” button.
You will get the following form to paste your public key content.
Now try to build your Jenkins job, you will find in the console log that all your source code are ready under Jenkins job workspace.