• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • git-plugin
    • None

      When a local branch is checked out with name matching a remote branch, and the remote branch is rewritten, endless builds are triggered. This happens because the plugin finds multiple matching revisions, one in the local and one in the remote branch:

      Multiple candidate revisions
      Scheduling another build to catch up with <build name>

      This can be solved by using the fully qualified remote branch name as specifier, i.e. "remotes/origin/branchname". But this is not possible in my case since the branch name is generated by the multibranch plugin.

      A simple fix might be to delete the automatic local branch before trying to match branch names; the local branch is anyway deleted a bit later, before it is recreated:

      Multiple candidate revisions
      Scheduling another build to catch up with <build name>
      Checking out Revision <revision> (<local branch name>)
      > git config core.sparsecheckout # timeout=10
      > git checkout -f <revision>
      > git branch -a -v --no-abbrev # timeout=10
      > git branch -D <local branch name> # timeout=10
      > git checkout -b <local branch name> <revision>

      ...or, alternatively, exclude the automatic local branch explicitly from the branch name matching.

       

          [JENKINS-54102] Endless builds with local branch checked out

          Joachim Haga added a comment -

          A workaround is to add a shell (or batch) build step,

          git checkout ${GIT_COMMIT}   # to detach, otherwise the delete below fails
          git branch -D ${GIT_LOCAL_BRANCH}
          

          Joachim Haga added a comment - A workaround is to add a shell (or batch) build step, git checkout ${GIT_COMMIT} # to detach, otherwise the delete below fails git branch -D ${GIT_LOCAL_BRANCH}

          Frigo Coder added a comment - - edited

          I experience the same with a release Jenkins job that is supposed to be started manually.

          The job is supposed to wipe release branch, branch test to release, commit a new release version into pom.xml, and of course push. There is no SCM polling or anything similar anywhere, yet it detects its own Git changes and starts itself in an infinite loop.

          I suspect this is a bug in Git itself rather than the Git Plugin. When I git pull on my local machine, the release branch is not replaced with the new one branched from test. Rather, it still shows some old commit history full of merges.

          Here is the bash script that triggers the bug:

          #!/bin/bash
          set -euf -o pipefail
          main () {
              local RELEASE=$1
              local SNAPSHOT=$2
              tag $RELEASE
              test_to_release $RELEASE
              advance_master $SNAPSHOT
          }
          tag () {
              local RELEASE=$1
              local COMMIT=$(git rev-parse test)
              git tag --force $RELEASE $COMMIT
              git push --force --tags
          }
          test_to_release () {
              local RELEASE=$1
              git checkout test
              git branch --force release
              git checkout release
              change_version $RELEASE "Release $RELEASE"
              git push --force origin release
          }
          advance_master () {
              local SNAPSHOT=$1
              git checkout master
              change_version "$SNAPSHOT-SNAPSHOT" "Snapshot $SNAPSHOT-SNAPSHOT"
              git push
          }
          change_version () {
              local VERSION=$1
              local MESSAGE=$2
              mvn versions:set -DnewVersion=$VERSION
              rm --force pom.xml.versionsBackup
              git commit --all --allow-empty --message="$MESSAGE"
          }
          main "$@" 

           

          Frigo Coder added a comment - - edited I experience the same with a release Jenkins job that is supposed to be started manually. The job is supposed to wipe release branch, branch test to release, commit a new release version into pom.xml, and of course push. There is no SCM polling or anything similar anywhere, yet it detects its own Git changes and starts itself in an infinite loop. I suspect this is a bug in Git itself rather than the Git Plugin. When I git pull on my local machine, the release branch is not replaced with the new one branched from test. Rather, it still shows some old commit history full of merges. Here is the bash script that triggers the bug: #!/bin/bash set -euf -o pipefail main () { local RELEASE=$1 local SNAPSHOT=$2 tag $RELEASE test_to_release $RELEASE advance_master $SNAPSHOT } tag () { local RELEASE=$1 local COMMIT=$(git rev-parse test) git tag --force $RELEASE $COMMIT git push --force --tags } test_to_release () { local RELEASE=$1 git checkout test git branch --force release git checkout release change_version $RELEASE "Release $RELEASE" git push --force origin release } advance_master () { local SNAPSHOT=$1 git checkout master change_version "$SNAPSHOT-SNAPSHOT" "Snapshot $SNAPSHOT-SNAPSHOT" git push } change_version () { local VERSION=$1 local MESSAGE=$2 mvn versions:set -DnewVersion=$VERSION rm --force pom.xml.versionsBackup git commit --all --allow-empty --message= "$MESSAGE" } main "$@"  

            Unassigned Unassigned
            jobh Joachim Haga
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: