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

"Merge before build" does not fetch updated merge target

    • Icon: Improvement Improvement
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • git-plugin
    • Ubuntu 14.04
      Jenkins 2.16
      Git plugin 3.0.1

      As part of our pull request workflow, we want Jenkins to try merging the pull request branch with the merge target.  We're using the "Stash pullrequest builder" plugin to poll the repo and provide the branch specifiers for both the pull request branch and the merge target to the Git plugin.

      In the configuration, we get (emphasizing important items):

      • "Branches to build" branch specifier: origin/pr/${pullRequestId}/from
      • "Additional behaviors", "Merge before build" has options:
        • Name of repository: origin
        • Branch to merge to: ${targetBranch}
        • Merge strategy: default
        • Fast-forward mode: --ff

      Unfortunately, while the Git plugin will fetch the item under "Branches to build", it does not fetch the "Branch to merge to", which means that it always merges with the wrong commit after the branch has moved in the upstream repo.

      To work around this, we're using "Wipe out repository and force clone", but it's a clumsy solution that won't scale up for larger repositories.

      One possible way to address the issue: "Merge before build" could automatically fetch the merge target

      Alternate possibility that might be valuable for other uses too: add a new "Additional behavior" that allows fetching specific refs.

      Please let me know if you need any additional information!

          [JENKINS-43485] "Merge before build" does not fetch updated merge target

          Mark Waite added a comment -

          Couldn't you just add the refspec of the target branch to the "Advanced" section of the repository definition so that it will be fetched in addition to the fetch of the pull request?

          Mark Waite added a comment - Couldn't you just add the refspec of the target branch to the "Advanced" section of the repository definition so that it will be fetched in addition to the fetch of the pull request?

          Gregory Fong added a comment - - edited

          markewaite , thanks for the quick response.  I thought that only supported a single refspec because the documentation for that feature didn't suggest otherwise.  However, since you mentioned that, I did a search and see that you updated this documentation in version 3.1.0 of the git plugin.  That'll do nicely, appreciate the help!

          Gregory Fong added a comment - - edited markewaite  , thanks for the quick response.  I thought that only supported a single refspec because the documentation for that feature didn't suggest otherwise.  However, since you mentioned that, I did a search and see that you updated this documentation in version 3.1.0 of the git plugin .  That'll do nicely, appreciate the help!

          Mark Waite added a comment -

          I would love confirmation that the multiple refspec technique worked for you. Good luck

          Mark Waite added a comment - I would love confirmation that the multiple refspec technique worked for you. Good luck

          Gregory Fong added a comment -

          Confirmed using the console log that it fetched all provided refspecs.

          Gregory Fong added a comment - Confirmed using the console log that it fetched all provided refspecs.

            Unassigned Unassigned
            gregoryfong_vg Gregory Fong
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: