Is there a good way to trigger a webhook from Bitbucket Server whenever a commit is pushed to an open pull request? I am currently using the "Pull Request Opened" webhook event to trigger a CI build (recipient is a Jenkins server), which works well for building newly created PRs. However, there doesn't seem to be an event for when a new commit is pushed to the repository branch that a PR is watching. The "Pull Request Opened" event does not handle this event.
While the Atlassian support page for Bitbucket Server webhooks does not mention this, there is a event for "Pull Request Modified" that is mentioned in a different support page. "Modified" sounds close to what I want, but it doesn't cover a new commit. Here is the description on the Bitbucket Server Webhooks edit page:
A pull request's description, title, or target branch is changed.
Sure enough, testing with the "Modified" event enabled does not trigger a webhook when a new commit is pushed to a PR branch. I'm starting to think that there are only two other methods:
- Trigger a webhook on every push, and have the CI server check to see if that commit is targeting a branch that the Bitbucket Server has an open PR for (using the REST API of Bitbucket Server). This would be undesirable, because the CI server would have to check every new commit, unnecessarily consuming time from the build agents.
- Write a post-commit hook onto the Bitbucket server that manually checks for an open PR targeting that commit's branch and writing a POST to a designated URL. I don't know if there's an easy way to do this other than having the hook script call the Bitbucket Server REST API to check for open PRs.