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

Jenkins checks out previous commit when new commit added to Pull Request

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When a pull request is created, Jenkins starts a build which checks out the correct commit. When another commit is pushed to the pull request branch, Jenkins starts another build. However, after the new commit is added, Jenkins sometimes checks out the first commit and not the 2nd.

      This issue is intermittent, sometimes Jenkins checks out the correct commit, sometimes it checkout out the previous commit.

        Attachments

          Activity

          Hide
          ee2284b30c Alexander Gerock added a comment -

          Stash Pull Request Builder Plugin uses Stash REST API to check for changes on pull requests:

          • https://<YOUR-HOST>/stash/rest/api/1.0/projects/<PROJECT>/repos/<REPO>/pull-requests/

          If a new commit is present build job is started

          • last revision is retrieved by
            • git fetch --tags --progress <GIT-REPO-URL> +refs/pull-requests/:refs/remotes/origin/pr/
            • git rev-parse refs/remotes/origin/pr/<PR-ID>/from^ {commit}

          The problem is that after pushing a commit on a branch for wich a pull request exists these changes are retrieved immediately by REST API but refs are not updated so that build job checks out not the latest commit.

          The pull request (refs) is only updated if the following call is made:

          • https://<YOUR-HOST>/stash/rest/api/latest/projects/<PROJECT>/repos/<REPO>/pull-requests/<PR-ID>/merge

          This call is made if you open a pull request in stash web page. This is the official solution:

          Workaround for Stash Pull Request Builder Plugin:

          • Activate "Build only if PR is mergeable" of Stash Pull Requests Builder on Jenkins to enforce REST API call to .../merge

          Possible solution:

          • Always call https://<YOUR-HOST>/stash/rest/api/latest/projects/<PROJECT>/repos/<REPO>/pull-requests/<PR-ID>/merge if there are changes on https://<YOUR-HOST>/stash/rest/api/1.0/projects/<PROJECT>/repos/<REPO>/pull-requests/
          Show
          ee2284b30c Alexander Gerock added a comment - Stash Pull Request Builder Plugin uses Stash REST API to check for changes on pull requests: https://<YOUR-HOST>/stash/rest/api/1.0/projects/<PROJECT>/repos/<REPO>/pull-requests/ If a new commit is present build job is started last revision is retrieved by git fetch --tags --progress <GIT-REPO-URL> +refs/pull-requests/:refs/remotes/origin/pr/ git rev-parse refs/remotes/origin/pr/<PR-ID>/from^ {commit} The problem is that after pushing a commit on a branch for wich a pull request exists these changes are retrieved immediately by REST API but refs are not updated so that build job checks out not the latest commit. The pull request (refs) is only updated if the following call is made: https://<YOUR-HOST>/stash/rest/api/latest/projects/<PROJECT>/repos/<REPO>/pull-requests/<PR-ID>/merge This call is made if you open a pull request in stash web page. This is the official solution: https://answers.atlassian.com/questions/239988/change-pull-request-refs-after-commit-instead-of-after-approval-or-workaround Workaround for Stash Pull Request Builder Plugin: Activate "Build only if PR is mergeable" of Stash Pull Requests Builder on Jenkins to enforce REST API call to .../merge Possible solution: Always call https://<YOUR-HOST>/stash/rest/api/latest/projects/<PROJECT>/repos/<REPO>/pull-requests/<PR-ID>/merge if there are changes on https://<YOUR-HOST>/stash/rest/api/1.0/projects/<PROJECT>/repos/<REPO>/pull-requests/
          Hide
          jimklimov Jim Klimov added a comment -

          Thanks to the detailed information above, I crafted an alternative solution of `curl`ing the needed REST API endpoint as a step in the triggered build.

          This take on working around this Stash feature is posted in the plugin's Wiki page at https://wiki.jenkins.io/display/JENKINS/Stash+pullrequest+builder+plugin?focusedCommentId=135464102#comment-135464102 

          Show
          jimklimov Jim Klimov added a comment - Thanks to the detailed information above, I crafted an alternative solution of `curl`ing the needed REST API endpoint as a step in the triggered build. This take on working around this Stash feature is posted in the plugin's Wiki page at https://wiki.jenkins.io/display/JENKINS/Stash+pullrequest+builder+plugin?focusedCommentId=135464102#comment-135464102  
          Hide
          jimklimov Jim Klimov added a comment -

          PRed my take on this issue as https://github.com/jenkinsci/stash-pullrequest-builder-plugin/pull/22 - to have a checkbox to poll that REST API and disregard the results (mergeable or not, conflicts or not - proceed with the build).

          Show
          jimklimov Jim Klimov added a comment - PRed my take on this issue as https://github.com/jenkinsci/stash-pullrequest-builder-plugin/pull/22  - to have a checkbox to poll that REST API and disregard the results (mergeable or not, conflicts or not - proceed with the build).

            People

            Assignee:
            jbochenski Jakub Bochenski
            Reporter:
            kevinsheedy Kevin Sheedy
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: