I am using a local BitBucket server with Git. I am trying to get started with Continous Integration so I've set up a local Jenkins instance. The goal is to have Jenkins check out pull-requests and build the project, and then report back to BitBucket with the result.
In BitBucket I am using Webhook to Jenkins for Stash which notifies my Jenkins instance each time a pull-request is created/updated.
In Jenkins i am using Stash pullrequest builder plugin to have Jenkins checkout the pullrequest, when notified from the plugin above. I have used the settings in the documentation, i.e.
Refspec: +refs/pull-requests/*:refs/remotes/origin/pr/*
Branch Specifier: origin/pr/${pullRequestId}/from
It almost works...
When i create a new pull request in BitBucket, Jenkins get nofitied, checks out the PR and report the result back to BitBucket. So far so good.
However when I update the PR (i.e. commit new code and push to BitBucket), Jenkins gets triggered but still checks out the previous commit in the PR, and not the new commit.
I've done some investegation but got stuck. From what I understand Refspec
specifies that i should map refs/remotes/origin/pr/*
to refs/pull-requests/*
locally. However it does not seem like BitBucket updates the refs for the PR when i do a new commit to an existing PR, which causes Jenkins only to find the old one.
When I run git ls-remote origin
after commiting and pushing an update to an existing PR i get this:
edf245 (new commit)... refs/heads/feature/Name-Of-My-Branch-That-I-Created-Pull-Request-From-pr
af774f (previous commit in PR)... refs/pull-requests/69/from
7fa82b (master)... refs/pull-requests/69/merge
However after visiting the PR-page in BitBucket, the refs seems to be updated and i get the following result:
edf245 (new commit)... refs/heads/feature/Name-Of-My-Branch-That-I-Created-Pull-Request-From-pr
edf245 (new commit)... refs/pull-requests/69/from
7fa82b (master)... refs/pull-requests/69/merge
And if i manually trigger Jenkins after this it build the latest commit.
So my problem is that BitBucket does not seem to upfate the refspec until I visit the acutal PR-page in BitBucket. How can i fix this?
Googling the problem I ended up here where it seems like the behaviour is by design...
See Question&Answers more detail:
os