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

Git builds with detached head no matter what

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • git-plugin
    • None
    • Ubuntu 10.04 amd64

    Description

      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.

      Attachments

        Issue Links

          Activity

            markewaite Mark Waite added a comment -

            itaiganot please refer to the comment prior to your question.

            The "pipeline syntax" link on the left of most pipeline job pages will open a page where you can prototype the code you need to perform a checkout to a specific branch. Use the "checkout" selection from that list (not the "git" selection), then select "Git" and add the "Additional Behaviours" for "Check out to specific local branch". You can then set a specific branch name, or you can use "**" to indicate that it should use the branch name from the repository where the clone was performed.

            markewaite Mark Waite added a comment - itaiganot please refer to the comment prior to your question . The "pipeline syntax" link on the left of most pipeline job pages will open a page where you can prototype the code you need to perform a checkout to a specific branch. Use the "checkout" selection from that list (not the "git" selection), then select "Git" and add the "Additional Behaviours" for "Check out to specific local branch". You can then set a specific branch name, or you can use "**" to indicate that it should use the branch name from the repository where the clone was performed.
            itaiganot Itai Ganot added a comment -

            Thanks, it did solve my first issue.

            But now I have another issue which is also related, I'd like to set:

            // currentBuild.displayName = "#${BUILD_NUMBER}|${BRANCH_NAME}" 
            

            And it cannot be done in pipeline because of the same reason... what can be done to achieve that?

            itaiganot Itai Ganot added a comment - Thanks, it did solve my first issue. But now I have another issue which is also related, I'd like to set: // currentBuild.displayName = "#${BUILD_NUMBER}|${BRANCH_NAME}"   And it cannot be done in pipeline because of the same reason... what can be done to achieve that?
            markewaite Mark Waite added a comment -

            itaiganot please don't use closed bug reports as a forum for questions. You're asking for time from the very few people who read git plugin bug reports, when there are much larger groups (like the Jenkins users mailing list) that can address your questions.

            markewaite Mark Waite added a comment - itaiganot please don't use closed bug reports as a forum for questions. You're asking for time from the very few people who read git plugin bug reports, when there are much larger groups (like the Jenkins users mailing list) that can address your questions.

            Isn't it enough to do the following to get a proper branch head at some point after the checkout?  It seems to work for me. 

            git checkout -b ${GIT_BRANCH} origin/${GIT_BRANCH}

            raulsalinasmonteagudo Raúl Salinas-Monteagudo added a comment - Isn't it enough to do the following to get a proper branch head at some point after the checkout?  It seems to work for me.  git checkout -b ${GIT_BRANCH} origin/${GIT_BRANCH }
            markewaite Mark Waite added a comment - - edited

            Yes, the git checkout command you used is a very good choice, especially if you're not using authenticated submodules or authenticated access to large file storage (git LFS).

            markewaite Mark Waite added a comment - - edited Yes, the git checkout command you used is a very good choice, especially if you're not using authenticated submodules or authenticated access to large file storage (git LFS).

            People

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

              Dates

                Created:
                Updated:
                Resolved: