Git Plugin

This plugin allows use of GIT as a build SCM. Git 1.3.3 or newer is required.

Plugin Information

Plugin ID git
Latest Release 0.8
Latest Release Date Jan 07, 2010
Changes via Fisheye In Latest Release
Since Latest Release
Maintainer(s) n/a (id: magnayn)
Issue Tracking Open Issues

Download latest version 0.7.3

Bugs

  • Check the open issues carefully to see if the issue has already been reported
  • Create an issue if needed, and make sure to choose the git sub-component.  Make sure to mention the plugin version number in the issue description.

Note for contributors: Please read SVN_USERS_PLEASE_READ_MEproperly before checking out the sources.  Those instructions are useful if you wish to use Git to contribute and request Nigel Magnay to pull your changes.

Gotchas

  • If you are seeing output indicating Git could not clone, something like the output below, go to to the Hudson configuration settings (not the project settings, the global ones) and change the Git path to a fully qualified path (eg. not "git" but "/usr/bin/git" or wherever your Git binary is installed). You should also verify that the permissions are correct if you are doing a file system based clone.
Started by user anonymous
Checkout:workspace / C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace - hudson.remoting.LocalChannel@1a1f370
Last Build : #4
Checkout:workspace / C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace - hudson.remoting.LocalChannel@1a1f370
Cloning the remote Git repository
Cloning repository origin
$ git clone -o origin git://github.com/bret/watir.git "C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace"
Trying next repository
ERROR: Could not clone from a repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:400)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:358)
    at hudson.FilePath.act(FilePath.java:676)
    at hudson.FilePath.act(FilePath.java:660)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:358)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:833)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:314)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:266)
    at hudson.model.Run.run(Run.java:948)
    at hudson.model.Build.run(Build.java:112)
    at hudson.model.ResourceController.execute(ResourceController.java:93)
    at hudson.model.Executor.run(Executor.java:118)
  • You man need to tell git who the user hudson is running as is. To do this on a Linux/Unix system edit the user's entry in /etc/passwd to set their login shell to /bin/bash instead of /bin/false. Then switch to that user which is probably tomcat6. Do this by using either of the following.
    $ su tomcat6
    $ sudo su tomcat6
    

    Now cd to the directory where the clone hudson created is and use git config user.name and git config user.email to set the values.

    $ cd /srv/hudson/jobs/project/workspace
    $ git config user.email "some@email.com"
    $ git config user.name "hudson"
    

    When you are done, log off as the hudson user and change the login shell back to /bin/false

Changelog

Version 0.7.3

FIXME this changelog entry is incomplete! Please give me some love!

  • [FIXED HUDSON-2931] git tag freezing job execution (jbq)
  • Improve log messages (jbq)
  • Use build listener to report messages when pushing tags to origin (jbq)
  • [FIXED HUDSON-2762] Fail to clone a repository on Windows (jbq)

Version 0.5

  • Fix git plugin which was very broken when running on a remote server (magnayn)
  • Fix NPE in GitChangeLogParser upon project's first build (jbq)
  • Change workspace to a FilePath in GitAPI (jbq)
  • Use git rev-list once instead of invoking git rev-parse indefinitely to find last build, see Issue 2469: GIT plugin very slow (jbq)
  • Handle null-value of the repositories field to ensure backwards-compatibility with version 0.3,
    ie when the project configuration is missing the <repositories/> XML element (jbq)
  • Improve error handling in revParse() (jbq)
  • Fix handling of the "branch" configuration parameter (jbq)
  • Improve tag handling, use show-ref instead of rev-parse to resolve the tag reference (jbq)
  • Fix Issue 2675: Git fails on remote slaves (jbq)

Version 0.4 (never released)

  • Allow multiple GIT repositories to be specified (magnayn)
  • Allow submodule configurations to be generated on the fly (magnayn)
  • Avoid infinite loops when git doesn't contains tags (david_calavera)
  • Don't do a log of the entire branch if it's never been built (magnayn)

 Version 0.3

  • Add support for pre-build branch merges

 Version 0.2

  • Improve handling of git repositories (use local tags to identify up to date versions rather than the wc HEAD)
  • Don't have to specify a branch, in which case all branches are examined for changes and built
  • Includes a publisher which can be used to push build success/failure tags back up to the upstream repository

 Version 0.1

  • Initial Release

Advanced Features

Using Git, Hudson and pre-build branch merging

Continuous Integration tools such as Hudson are useful on projects as they give users early indication that a particular codebase is 'unstable' - and that if a developer checks it out, there will be trouble ahead (they won't be able to work on their own code, because someone else has broken something).

Unfortunately, by the time the build completes, this is often too late (particularly if the build cycle time is very long), as a developer has updated their working copy to the latest, unstable code in the repository and has begun work.

This can lead to the code base remaining unstable as developers tread on each others toes steadily fixing one thing, but breaking something else.

Some environments (e.g. TeamCity) attempt to fix this by making commits into SVN only 'really' happen once they have been tested. These kinds of 'delayed-commits' are problematic, because local SCM tools assume that commits will be immediately available, which can confuse them. In many ways this mechanism is a hack to get around the fact that branch management in SVN is very heavyweight.

Fortunately, with GIT and Hudson, you can achieve the same 'stable branches' with minimal effort.

Set up your hudson project, and leave the 'branch' field in the Git SCM blank. This will cause Hudson to consider any change on any branch for building.

Next, pick a particular branch name as the integration target in the 'Advanced' section - (e.g. 'master', or 'stable'), and select 'Merge before build'.

Select 'Push GIT tags back to origin repository' from the post-build actions (this is required to update your centralised git repo with the results of the build).

Now, developers should never commit directly to your integration branch (the 'master' or 'stable'). Instead, they should either use feature branches, or create new remote branches on commit (e.g : "git push origin HEAD:refs/heads/myNewFeature"). You could also set up your GIT repository to only accept commits onto the integration branch from Hudson.

You're done. Commits should now be automatically merged with the integration branch (they will fail if they do not merge cleanly), and built. If the build succeeds, the result of the merge will be pushed back to the remote git repository.

Using Extra Repositories

Since GIT is a Distributed SCM, it is possible in the Advanced section to specify multiple repositories. You may wish to do this to, for example, pull all in-progress work from individual developers machines, and pre-test them before they are committed to a centralised repository - this way developers may get an early warning that a branch in progress may not be stable.

The GIT plugin will make reasonable attempts to try and pull submodule states from distributed repositories, with the proviso that this feature is not currently well supported within GIT itself.

Autogenerate submodule configurations

A common development pattern for many users is the use of a 'superproject' that aggregates a number of submodules. For example, ProjectA may have ComponentA, ComponentB and ComponentC. ComponentA is a shared library, and is set to use a particular revision (maybe on a branch called 'ProjectA' in case there are any changes). Usually, any changes to the project configuration require a commit to the ProjectA superproject.

However - there could be other changes happening on other branches of ComponentA (say to the development of the next version). Without someone generating commits into ProjectA to test these, any regressions or incompatibilities may be missed.

The autogenerate submodule configurations feature will create commits into ProjectA for all possible combinations of the branches present in the submodules that the project uses.

Labels:

plugin-scm plugin-scm Delete
Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.
  1. Jun 23, 2009

    Kohsuke Kawaguchi says:

    Through rtyler: http://github.com/stephenh/git-central/blob/master/server/post-r...

    Through rtyler: http://github.com/stephenh/git-central/blob/master/server/post-receive-hudson automates the set up of a Hudson job whenever a new branch is created. Nice.

  2. Jul 22, 2009

    J. Longman says:

    How do I build a specific revision? I used to be able to specify a build should ...

    How do I build a specific revision? I used to be able to specify a build should use SHA1-ID, like build origin/bdbbfc3f0e9c57fbeff89de2ad7ca308a168575e and it would work.  This is necessary for reproducibility.

    Has this changed? How do I do this now?

  3. Nov 17

    Kenneth P. Turvey says:

    I wrote a tutorial on getting hudson to work with git and grails.  It inclu...

    I wrote a tutorial on getting hudson to work with git and grails.  It includes all the information necessary to set up an integration server using git and hudson even if you aren't interested in grails development:

    http://www.electricsenator.net/2009/10/03/1254618530821.html

  4. Nov 18

    Graeme Simpson says:

    Is it possible to use credentials when accessing a git repository? Or certificat...

    Is it possible to use credentials when accessing a git repository? Or certificates?

    Thanks,
    Graeme

  5. Jan 01

    Chas Emerick says:

    Is there any way to get the git plugin to checkout ref names instead of the sha'...

    Is there any way to get the git plugin to checkout ref names instead of the sha's associated with remote refs? Not being on a branch in the course of a build is causing issues (for at least two of us) in conjunction with the M2 Release Plugin:

    Can’t get automated release working with Hudson + Git + Maven Release Plugin

    1. Feb 02

      Chas Emerick says:

      This issue has been resolved for me as of v0.8.0 of the git plugin.  See my...

      This issue has been resolved for me as of v0.8.0 of the git plugin.  See my comment below.

  6. Jan 06

    Brad Robertson says:

    I can't get Hudson to merge into the master branch. It always ends up in *no br...

    I can't get Hudson to merge into the master branch. It always ends up in *no branch, which is no good to me as I want to push master to another remote repo as a deploy.
    I've set the following:
    refspec: +refs/heads/master:refs/remotes/origin/master
    branch to build: */master
    branch to merge to: master

    The Git logs show it fetching the latest, then for some reason checking out the previous version with the sha, which puts it into *no branch. Then it does a git merge with the latest, still on *no branch. I've included the logs below.

    I don't think this is the correct behavior given that I specify that I want to merge to the master branch. Thoughts? Bug?

    Git logs from hudson:
    git fetch /home/git/repositories/my_repo.git +refs/heads/master:refs/remotes/origin/master
    git ls-tree HEAD
    git rev-parse master
    git checkout -f old_rev_sha here's where it switches branches
    git merge new_rev_sha

    1. Jan 08

      Chas Emerick says:

      I don't know if this is a bug, but +1 that this isn't correct behaviour IMO (see...

      I don't know if this is a bug, but +1 that this isn't correct behaviour IMO (see my comment directly above yours).

      1. Jan 09

        Brad Robertson says:

        ya i read that. I'm also confused as to why it's using sha's, especially when t...

        ya i read that. I'm also confused as to why it's using sha's, especially when the plugin allows you to specify the ref you want and the branch to merge to.

        I personally do think it's a bug if you are specifying the branch to merge to and the fetched code is not merged to that branch

        1. Feb 02

          Chas Emerick says:

          I upgraded to v0.8.0 of the git plugin, and have been able to perform a maven re...

          I upgraded to v0.8.0 of the git plugin, and have been able to perform a maven release using the Maven release plugin, and have the results successfully pushed back to master.

          v0.8.0 appears to add a "Merge options" section (in the advanced tab under the SCM section of the project config).  I put "origin" in 'name of repository' and "master" in 'branch to merge to', and the push went swimmingly.

  7. Jan 11

    Anonymous ultimo says:

    Problems with new 0.8 version under windows. It looks very good and the new inf...

    Problems with new 0.8 version under windows.

    It looks very good and the new information about changed files is great but scm polling doesn't work anymore

    1. yesterday at 12:51 PM

      J. Longman says:

      I'm also having problems, but I'm not using windows: Feb 8, 2010 11:51:03 AM h...

      I'm also having problems, but I'm not using windows:

      Feb 8, 2010 11:51:03 AM hudson.triggers.SCMTrigger$Runner runPolling
      SEVERE: Failed to record SCM polling
      java.lang.NullPointerException
      	at hudson.plugins.git.GitSCM.pollChanges(GitSCM.java:254)
      	at hudson.model.AbstractProject.pollSCMChanges(AbstractProject.java:1067)
      	at hudson.triggers.SCMTrigger$Runner.runPolling(SCMTrigger.java:319)
      	at hudson.triggers.SCMTrigger$Runner.run(SCMTrigger.java:346)
      	at hudson.util.SequentialExecutionQueue$QueueEntry.run(SequentialExecutionQueue.java:118)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
      	at java.lang.Thread.run(Thread.java:619)
      
      Solved by adding executors to my master