# Configuring Bitbucket Cloud project binding

## Reporting your quality gate status in Bitbucket Cloud for unbound projects

On SonarQube Server projects bound to their Bitbucket Cloud repository, SonarQube Server automatically sets up the report of your quality gate status and analysis metrics directly to your pull requests.&#x20;

You can bind an existing and manually created project to its Bitbucket Cloud repository provided the global integration of SonarQube Server with Bitbucket Cloud has been properly set up. To do so, see [changing-project-binding](https://docs.sonarsource.com/sonarqube-server/project-administration/maintaining-project/changing-project-binding "mention").

## Preventing pull request merges when the quality gate fails

After setting up a pull request analysis, you can block pull requests from being merged if it is failing the quality gate. To do so, you configure a branch restriction. The set up is different whether you use Bitbucket Pipelines or not.

### Prerequisites

You need the Premium Bitbucket Cloud plan.

{% hint style="warning" %}
Preventing pull request merges when the quality gate fails is not supported for monorepos.
{% endhint %}

### **With Bitbucket Pipelines**

You must make sure that the Bitbucket Pipeline fails when the quality gate fails. See [#failing-the-pipeline-job-when-the-quality-gate-fails](https://docs.sonarsource.com/sonarqube-server/analyzing-source-code/ci-integration/bitbucket-pipelines#failing-the-pipeline-job-when-the-quality-gate-fails "mention").

Configure a branch restriction as follows:

1. In Bitbucket, go to **Repository settings** > **Branch restrictions** to either **Add a branch restriction** or edit your existing one.
2. In the **Merge settings** tab:
   * Set **Minimum number of successful builds for the last commit with no failed builds and no in progress builds** to **1.**
   * Select the **Prevent a merge with unresolved merge checks** option.

<div align="left"><figure><img src="broken-reference" alt="Adding a branch restriction" width="563"><figcaption></figcaption></figure></div>

### **Without Bitbucket Pipelines**

If you know how many builds you have for a pull request, you can run your SonarQube Server analysis and not block the pipeline waiting for results. The SonarQube Server Quality Gate will appear in the build for your pull request after the analysis results are available.

Configure a branch restriction as follows:

1. In Bitbucket, go to **Repository settings** > **Branch restrictions** to either **Add a branch restriction** or edit your existing one.
2. In the **Merge settings** tab, set **Minimum number of successful builds for the last commit with no failed builds and no in progress builds** to the number of builds that run for the pull request. The figure below shows an example with 2 builds.

<div align="left"><figure><img src="broken-reference" alt="Define the number of builds to pass in Bitbucket Cloud before allowing pull requests to pass."><figcaption></figcaption></figure></div>

## Related pages

[bitbucket-cloud](https://docs.sonarsource.com/sonarqube-server/instance-administration/devops-platforms/bitbucket-cloud "mention")\
[import-repos](https://docs.sonarsource.com/sonarqube-server/project-administration/creating-project/bitbucket-cloud/import-repos "mention")\
[bitbucket-pipelines](https://docs.sonarsource.com/sonarqube-server/analyzing-source-code/ci-integration/bitbucket-pipelines "mention")\
[Broken link](https://docs.sonarsource.com/sonarqube-server/project-administration/creating-project/bitbucket-cloud/broken-reference "mention")
