Jenkins Git Server Plugin

Written by: Kohsuke Kawaguchi

Jenkins Git Server plugin  is a so-called "library plugin", which doesn't offer any user-visible features by itself, but instead enables other plugins to do something easily inside Jenkins. In case of Git server plugin, it allows other plugins to easily embed Git server functionality (via  JGit ) — create/manipulate Git repositories in the Jenkins server, expose it via SSH and HTTP transport for push/pull, and maintain local check out of those repositories.

As an example of how to use this plugin, I wrote Git userContent plugin . This plugin exposes the $JENKINS_HOME/userContent  directory as a Git repository, and enables administrators to use Git to push/pull changes and manage them with history.

In terms of code, there are two classes that plugins like git-userContent-plugin  should be interested in:

  1. One is HttpGitRepository , which represents Git repository access via HTTP. Typically you have some directory inside $JENKINS_HOME  that houses the repository, then you subtype GitHttpRepository  and override abstract methods to fill in the missing details. FileBackedHttpGitRepository  is a convenient default implementation that simplifies this further. GitUserContentRepository  in git-userContent-plugin  is an example of using this class. This use also implements RootAction  to bind this repository at http://server/jenkins/userContent.git, and I expect this combination to be fairly common.
  2. The other class of interest is RepositoryResolver . Git server plugin adds necessary Jenkins SSH  CLI hook for exposing Git repositories over SSH. The only missing link here is that when the client runs "git clone ssh://server/foo/bar/zot.git ", we need to figure out what repositories on the server correspond to /foo/bar/zot.git , and that's what the RepositoryResolver  extension point does. The sample implementation  in git-userContent-plugin  will be hopefully self-explanatory. In this case, GitUserContentRepository  is a singleton (because it's RootAction ), so we inject that and basically just delegate the calls to it.

I'm looking forward to seeing more plugins take advantage of this feature to expose data over Git repository. I think there are a lot of interesting uses for it.

Kohsuke Kawaguchi

Kohsuke Kawaguchi is the creator of Jenkins, writing the majority of the Jenkins core single-handedly, while at Sun. Kohsuke is also known for a number of other open-source projects, such as: args4j, YouDebug, com4j, Animal Sniffer, Sorcerer, wagon-svn, MSV, Parallel JUnit extension. Today Kohsuke is at CloudBees, where he spends his days bringing Jenkins to the cloud and making the Jenkins core even better.

See for more information about Kohsuke. You can also follow Kohsuke on Twitter.

Stay up to date

We'll never share your email address and you can opt out at any time, we promise.