Setting up Bitbucket Cloud integration for your project
How to set up Bibucket Cloud integration features for your SonarQube Server project.
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. For unbound projects, you must set up the quality gate status report manually. The integration of your SonarQube Server instance with Bitbucket Cloud must be properly set up.
To report your quality gate status in Bitbucket Cloud for unbound projects:
- In the SonarQube Server UI page of your project, select Project Settings > General Settings > DevOps Platform Integration. 
- Set: - Configuration name: The configuration name that corresponds to your Bitbucket Cloud instance. 
- Repository SLUG: The Repository SLUG is part of your Bitbucket Cloud URL. For example, - https://bitbucket.org/<workspace>/<repository>
 
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.
Preventing pull request merges when the quality gate fails is not supported for monorepos.
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.
Configure a branch restriction as follows:
- In Bitbucket, go to Repository settings > Branch restrictions to either Add a branch restriction or edit your existing one. 
- 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. 
 

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:
- In Bitbucket, go to Repository settings > Branch restrictions to either Add a branch restriction or edit your existing one. 
- 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. 

Related pages
Setting up Bitbucket Cloud integration at global level Importing Bitbucket Cloud repositories Adding analysis to Bitbucket pipeline Troubleshooting
Last updated
Was this helpful?

