Pull Request on merge commit not supported for Bitbucket Cloud and Azure Pipelines?
Asked by Ray Depew:

Our project repository is on Bitbucket Cloud. We are building using Azure Pipelines. Our triggers in the pipeline are set up in this fashion:

    trigger:- '*'pr:- develop- develop/*- master/*- feature/*- release_*

CI builds are triggered on every commit, as expected. PR builds are triggered when PRs are created or updated, but not when merged. We note that this is expected behavior for Bitbucket Cloud, per the Azure Devops [documentation](https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/bitbucket?view=azure-devops&tabs=yaml#pr-triggers) (emphasis is mine):
> Each new run builds the latest commit from the source branch of the pull request. This is different from how Azure Pipelines builds pull requests in other repositories (e.g., Azure Repos or GitHub), where it builds the merge commit. **Unfortunately, Bitbucket does not expose information about the merge commit**, which contains the merged code between the source and target branches of the pull request.

That is, a PR build is triggered when a PR is *created* or *updated* , but not on a *merge commit*.

That is indeed unfortunate. To correct this deficiency requires some cooperation between Microsoft and Atlassian. Is either party working on a solution? If not, is there a kludge or workaround we can use instead?  

EDITED TO ADD: This is not intended as a flame or a complaint. BB Cloud is great. I'm just trying to find a way to make this work.


Answers:
author: Ray Depew
body: We came up with two workarounds.

1. **PowerAutomate.** We created a [Microsoft Power Automate](https://make.powerautomate.com/) flow to do what we wanted. The flow uses the [Bitbucket Connector](https://powerautomate.microsoft.com/en-us/connectors/details/shared_bitbucket/bitbucket/) to capture a **WebhookPullRequestMergedResponse** , and the [Azure Devops Connector](https://powerautomate.microsoft.com/en-us/connectors/details/shared_visualstudioteamservices/azure-devops/) to queue an Azure Pipelines build. Unfortunately, these two connectors require a premium license, and we're not willing to pay for that right now. So, even though this is a good solution, we're not going to pursue it further.

2. **Our own little webserver.** We created our own [webhook(s)](https://support.atlassian.com/bitbucket-cloud/docs/manage-webhooks/) in the Bitbucket repository for PR events like **pullrequest:merged** . When a webhook is triggered, it sends a notification to a webserver that we have running on an existing Azure VM. The event payload is parsed, and a build request is sent to our our Azure DevOps build server, using the [Azure DevOps REST API](https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-7.1). This is the solution we're going with.

Either workaround adds another machine to the process flow, but that can't be avoided.


author: Theodora Boudale
body: Hi [@Ray Depew](/t5/user/viewprofilepage/user-id/4321549) ,

We have a feature request about this in our issue tracker:

* <https://jira.atlassian.com/browse/BCLOUD-20718>

If you're interested in that feature, I would suggest adding your vote there (by selecting the **Vote for this issue** link) as the number of votes helps the development team and product managers better understand the demand for new features. You are more than welcome to leave any feedback, and you can also add yourself as a watcher (by selecting the **Start watching this issue** link) if you'd like to get notified via email on updates.

Implementation of new features is done as per our policy [here](https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html) and any updates will be posted in the feature request.

Kind regards,  
Theodora

comments: author: Ray Depew
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) , thank you for the tip.

I added my vote to the Jira issue. With only six votes in 13 months, it might be a while before anybody gets around to it. (Insert smiley here, as appropriate.)

Just an observation: from the number of votes for the Jira issue, I infer that the number of SW Dev groups using Bitbucket Cloud in connection with Azure Pipelines is is a small number. Like 6, maybe?


author: Theodora Boudale
body: Hi Ray,

I don't have any info on the number of software development teams that use Bitbucket Cloud with Azure Pipelines, but I don't think that the number of votes in the feature request is indicative of that.

There may be teams using the integration that don't have that requirement for their builds. There may also be teams with that requirement that find another way to work around this issue (like with Ankit's suggestion) and/or may never contact Bitbucket Cloud support about this, so they may not be aware of the feature request.


author: Ankit Gupta
body: Hey Ray,

I haven't used Azure Pipelines, but looking at the documentation, can't you use the **branches** trigger? That would run whenever the PR gets merged.

Or is there some other use case you would like to solve with PR merged?

comments: author: Ray Depew
body: Yes, that's one option we're looking at.


Tags: azure

bitbucket-cloud

bitbucket-pipelines

cloud