Using Git with Jenkins

Overview

Git logoJenkins is a continuous integration server and this means it needs to check out source code from a source code repository and build code. Jenkins has excellent support for various source code management systems like CVS, Subversion, etc. Git is fast becoming one of the most popular source code management systems. Jenkins works with Git through the Git plugin.

This blog shows how to use Git with Jenkins. The GitHub plugin should be used if GitHub is the Git server of choice (Using GitHub with Jenkins blog).  

We will look at a vanilla set up that is configured to build manually (instead of polling the repo or receiving pushes from the repo). 

Stable Release Version

The current stable release is version 1.1.15 and was released in Dec 2011. 

Requirement for Plug-in Use

There are not too many requirements for using this plugin:
  • Jenkins 1.398 or newer
  • A git repository to talk to ;-)

Step-by-Step Instructions on How to Use the Git Plugin

Installation

  1. Go to your Jenkins instance’s root page.
  2. If your Jenkins instance has security enabled, login as a user who has the Overall | Administer permission.
  3. Select the Manage Jenkins link on the left-hand side of the screen.
  4. Select the Configure Jenkins link, give the path to the Git executable on the system or let Jenkins install it automatically.
  5. Go to the the Manage Plugins link.
  6. On the Available tab, select the Git Plugin and click the Download and Install button at the bottom of the page.
Git configuration

Configuration

  1. Go to your Jenkins instance job.
  2. Select the Configure link on the left hand side of the screen.
  3. In the Source Code Management field, enter the URL of the Git project which typically looks like: ssh://git@git.cloudbees.com/project.git.
Git repositoryThis sets up your job to checkout all branches on the particular Git repository. 

If you have remote branches set up and you would like to build a particular remote branch, add the branch name into the Branches to build the textbox

The Advanced tab gives a number of options that can be configured on the build. For example: if there is a specific Git user name that should be used, populate the 
 
Git Config user name

Config user.name and Config user.email values.

 

Tips & Tricks 

This plugin can be used to implement a pre-commit feature wherein commits are merged into a stable branch only if builds happen successfully on a development branch. A subsequent blog will outline this advanced usage. 

How to Use it on DEV@cloud/RUN@cloud

If you are using the CloudBees Platform as a Service (PaaS), the plugin is identical to configure on DEV@cloud except you do not need to install Git. 

Any Known Issues

  • There are plans to rewrite the plugin in the future to make the configuration easier. 
  • On Windows, additional steps are required to get the plugin working seamlessly. The steps are covered on the Jenkins Git plugin page.

Relevant Documentation

 
Thanks,
 
Harpreet Singh
Senior Director, Product Management
 

Learn More

Want to learn the latest in Jenkins? Subscribe to the Jenkins newsletter, Continuous Information. This monthly newsletter contains all of the latest interesting and useful happenings in the Jenkins community, sent directly to your inbox.