Set up Git and Jenkins under Ubuntu
＊ Install Git and set up Git
Git is a distributed version control system and can be installed using the following one command:
sudo apt-get install git
After it finishes downloading, you will have Git installed and ready to use. Use the following commands to config global username and email.
git config --global user.name "username"
git config --global user.email "email"
Use the following command to see all of your settings:
git config --list
＊ Set up a new Git project
After installing Git, you should be able to create a new Git project.
There are two types of repositories in Git: development repository and bare repository. A development repository is used for normal, daily development, e.g. editing, adding and deleting files. In contrast, a bare repository has no working directory and it serves as an authoritative basis for collaborative development. You can pull/push changes from/to bare repositories.
Use the following commands to set up a remote bare repository
git init --bare
After setting up bare repository, we need to init a local project and do a initial "push" to the bare repository. So on local machine, do the following:
git add *
git commit -m "Initial commit message"
# Add remote origin, specify your own project path
git remote add origin email@example.com:my_test_project.git
git push -u origin master
Others can clone the remote repository using the following command
git clone firstname.lastname@example.org:my_test_project.git
＊ Install Jenkins
Install Jenkins using the following command:
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
For more configurations, please refer to Installing Jenkins on Ubuntu
＊ Install Jenkins Git plugin
After installing Jenkins, you should be able to access Jenkins root page at http://your_jenkins_host:8080/
Next we should install Jenkins Git plugin to allow Jenkins to talk to Git repository. If your Jenkins instance has security enabled, login as a user who has the Overall/Administer permission.
Select Manage Jenkins link on the left-hand side of the screen. Click on Manage Plugins link.
Under Available tab search for "git" then you should be able to select the Git plugin.
Click the Download now and Install after restart button at the bottom.
＊ Configure job in Jenkins
Navigate to Jenkins instance job or create one if none exists.
Select Configure link on the left hand side of the screen In the Source Code Management select Git option and enter the previous git address which looks like ssh://email@example.com/my_test_project.git. Note: Make sure that the bare git repository is visible to Jenkins otherwise errors would be thrown.
For more information please refer to Jenkins Git Plugin Click Save button at the bottom.
＊ Configure Jenkins to build automatically after Git push
You may want to trigger Jenkins job to build automatically after each Git push. You can achieve this simply by using Git post-receive hook.
To do this, navigate to job configuration page by clicking on Configure link on the left hand side. Check Poll SCM option under Builder Triggers.
In the machine which holds Git bare repository, inside my_test_project.git folder, go into hooks folder and create a file called post-receive, and type in the following command:
Go to your Git development repository and do a Git push, you should see the following message.
"remote: Scheduled polling of my test project"