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

Merge before build, reference is not a tree on second build

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

      Pipeline Jenkins build with

      SCM: GIT

      Branches to build: refs/tags/*_${RELEASE}_feature

      Additional Behaviours: Merge before build

       

      first polled build is ok (change is detected and merged), see log

      second build triggered by hand gets error (no change), see log

       

        1. Jenkinsfile
          0.2 kB
        2. config.xml
          3 kB
        3. first-good.txt
          11 kB
        4. second-bad.txt
          4 kB

          [JENKINS-59008] Merge before build, reference is not a tree on second build

          Mark Waite added a comment - - edited

          Is SHA-1 a487d775943bc781fc0425601a15cb7445c67c6a a valid SHA-1 in any of the repositories involved in the (failing) second job? For example, are you using a pipeline shared library and is that SHA-1 one of the commits in the pipeline shared library?

          Was able to answer my own question. That must be a valid SHA-1 in the repository since the first build succeeds using the same SHA-1

          Mark Waite added a comment - - edited Is SHA-1 a487d775943bc781fc0425601a15cb7445c67c6a a valid SHA-1 in any of the repositories involved in the (failing) second job? For example, are you using a pipeline shared library and is that SHA-1 one of the commits in the pipeline shared library? Was able to answer my own question. That must be a valid SHA-1 in the repository since the first build succeeds using the same SHA-1

          Mark Waite added a comment -

          I don't know how to duplicate the conditions you're seeing. Refer to the JENKINS-51638 verification job and its contributor branch in the JENKINS-51638-project-1 branch for an example of what I've attempted.

          Does the "branches to build" need to be a tag? Does it behave differently if you use a branch instead of a tag? My test case did not attempt to use a tag, just two branches.

          Mark Waite added a comment - I don't know how to duplicate the conditions you're seeing. Refer to the JENKINS-51638 verification job and its contributor branch in the JENKINS-51638-project-1 branch for an example of what I've attempted. Does the "branches to build" need to be a tag? Does it behave differently if you use a branch instead of a tag? My test case did not attempt to use a tag, just two branches.

          P K added a comment -

          it should be a tag for my project and i can reproduce the error. i'll try branch later on.

          P K added a comment - it should be a tag for my project and i can reproduce the error. i'll try branch later on.

          Mark Waite added a comment -

          Can you provide the config.xml of the job? The failure mode is surprising, though it may be similar to a recent report related to tags and merges.

          Mark Waite added a comment - Can you provide the config.xml of the job? The failure mode is surprising, though it may be similar to a recent report related to tags and merges.

          P K added a comment -

          see the config attached...

          P K added a comment - see the config attached...

          Mark Waite added a comment -

          Thanks. A tag as a merge target will not work. I've confirmed that a branch merge target works as expected while a tag merge target fails consistently, whether in a multibranch Pipeline or a Pipeline job based on a single branch of a repository.

          I assume the first success case in your job may be a happy accident.

          If merge to a tag is critical, you can likely perform the merge step you want using sh or bat or powershell calls to command line git to perform the merge. Merge is a local operation in git (unless you're using large files) and should not require any credentials.

          Refer to my JENKINS-59008 check job to see the techniques I explored while trying to merge to a tag.

          Mark Waite added a comment - Thanks. A tag as a merge target will not work. I've confirmed that a branch merge target works as expected while a tag merge target fails consistently, whether in a multibranch Pipeline or a Pipeline job based on a single branch of a repository. I assume the first success case in your job may be a happy accident. If merge to a tag is critical, you can likely perform the merge step you want using sh or bat or powershell calls to command line git to perform the merge. Merge is a local operation in git (unless you're using large files) and should not require any credentials. Refer to my JENKINS-59008 check job to see the techniques I explored while trying to merge to a tag.

          P K added a comment - - edited

          i checked with a branch and it did not work either (do not forget that second build is triggered by hand and there is no change in git). I had to press "add Branch" in "Branches to build" because just changing field content had no effect on poller.

           

          P K added a comment - - edited i checked with a branch and it did not work either (do not forget that second build is triggered by hand and there is no change in git). I had to press "add Branch" in "Branches to build" because just changing field content had no effect on poller.  

          Mark Waite added a comment -

          I trigger second (and subsequent) builds by hand (interactive click of 'Build now') and merges with a branch target work as expected in all the cases I have (except the JGit case where a null pointer exception blocks the merge).

          In my success case, I am using the LocalBranch extension to assure that the repository in the workspace includes a branch.

          The Jenkinsfile you attached does not perform a merge. Maybe you used a different Jenkinsfile?

          Mark Waite added a comment - I trigger second (and subsequent) builds by hand (interactive click of 'Build now') and merges with a branch target work as expected in all the cases I have (except the JGit case where a null pointer exception blocks the merge). In my success case, I am using the LocalBranch extension to assure that the repository in the workspace includes a branch. The Jenkinsfile you attached does not perform a merge. Maybe you used a different Jenkinsfile?

          P K added a comment -

          i use Additional Behaviours: Merge before build !!

          Jenkinsfile just push on success

          P K added a comment - i use Additional Behaviours: Merge before build !! Jenkinsfile just push on success

          Mark Waite added a comment -

          My statement from earlier still applies. Merge with a target tag will not work. Merge with a target branch works in my tests, so long as I use the LocalBranch extension. Your config.xml does not use the LocalBranch extension. git merge needs a branch in the working repository. Without the LocalBranch extension, the git plugin performs a checkout of a detached HEAD with no branch defined.

          Mark Waite added a comment - My statement from earlier still applies. Merge with a target tag will not work. Merge with a target branch works in my tests, so long as I use the LocalBranch extension. Your config.xml does not use the LocalBranch extension. git merge needs a branch in the working repository. Without the LocalBranch extension, the git plugin performs a checkout of a detached HEAD with no branch defined.

          P K added a comment -

          "Branch to merge to" is always a branch in my case!

          I checked that "Branches to build" for tag and branch is the same

          P K added a comment - "Branch to merge to" is always a branch in my case! I checked that "Branches to build" for tag and branch is the same

          Mark Waite added a comment -

          But your job definition does not include the LocalBranch extension, at least not the job definition that is uploaded. Without the LocalBranch extension, the workspace which Jenkins creates for the job does not have a branch, it only has a detached HEAD commit. A detached HEAD commit is good enough for builds but is not good enough for a merge.

          Mark Waite added a comment - But your job definition does not include the LocalBranch extension, at least not the job definition that is uploaded. Without the LocalBranch extension, the workspace which Jenkins creates for the job does not have a branch, it only has a detached HEAD commit. A detached HEAD commit is good enough for builds but is not good enough for a merge.

          P K added a comment -

          do you mean to configure "Check out to specific local branch" before merge step?  - it did not help.... and merge to detached HEAD worked too, as you see in my log...

          P K added a comment - do you mean to configure "Check out to specific local branch" before merge step?  - it did not help.... and merge to detached HEAD worked too, as you see in my log...

          Mark Waite added a comment -

          Sorry, I don't know what's different between your failing cases and my working cases. I've completed my investigation and placed my results into publicly accessible locations. I'll rely on you to compare my working cases and your failing cases.

          Mark Waite added a comment - Sorry, I don't know what's different between your failing cases and my working cases. I've completed my investigation and placed my results into publicly accessible locations. I'll rely on you to compare my working cases and your failing cases. Jenkinsfile on first branch that confirms pre-build merge works with branch targets and confirms it does not work with tag targets Jenkinsfile on second branch that confirms pre-build merge works with branch targets and confirms it does not work with tag targets Docker image definition that uses the Jenkinsfile to run the job (and many others)

          P K added a comment -

          please add push at the end of your Jenkinsfile

          without push it works and has always somthing to merge!!!

          P K added a comment - please add push at the end of your Jenkinsfile without push it works and has always somthing to merge!!!

          P K added a comment -

          any progress on this?????

          P K added a comment - any progress on this?????

          Mark Waite added a comment -

          No progress and none planned.

          Mark Waite added a comment - No progress and none planned.

          P K added a comment -

          great! see my last comment and retest with push

          P K added a comment - great! see my last comment and retest with push

            Unassigned Unassigned
            petekol P K
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: