Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-6856

Git builds with detached head no matter what

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • git-plugin
    • None
    • Ubuntu 10.04 amd64

      The Git SCM plugin has suffered from this problem since I started using it. Rather than merge the changes to be built into a branch which tracks the remote I want to push to, it checks out one rev and merges the others on, resulting in a detached HEAD. My build expects to be run on a specific branch, and it fails because the repo isn't in that state.

      Other people have encountered the same problem, and there doesn't seem to be any solution other than to fix things in the build steps, which is a big hassle.

      Can we please get this issue resolved, or if it's been fixed, clear instructions on how to make it work?

      I've attached the SCM portion of my job's config.xml. What I'm trying to do is build changes committed to branches in the origin repo (SG), merge those into SG-gold/master and push them back to SG-gold/master.

      Here are the commands where things seem to go wrong:

      [SG-experimental] $ git rev-parse gold/master
      [SG-experimental] $ git checkout -f ceb23d234b1b21006f049d310501082b77b70ae4
      [SG-experimental] $ git merge 172b2d433ee57509f8e886f5d734f226d49166dd
      [SG-experimental] $ git tag -a -f -m "Hudson Build #35" hudson-SG-experimental-35
      Warning : There are multiple branch changesets here
      

      Rather than "git checkout gold/master", it finds the hash of gold/master and checks out that instead. This is the root of the problem.

      In order to fix this, you have to put these in the first build step:

      git branch -D temp_merge || true
      git branch temp_merge ${BUILD_TAG}
      git checkout master
      git reset --hard gold/master
      git merge temp_merge
      

      This is error-prone and requires duplication of the merge target branch that's already in the Git configuration for the job.

            abayer Andrew Bayer
            ieure ieure
            Votes:
            0 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved: