What is a quality gate?
A quality gate is the best way to enforce a quality policy in your organization. Setting up a quality gate allows you to prevent any code that doesn't pass code reviews from being merged into certain branches.
Key Benefits
Enforce code quality consistency across the entire project.
Ensure that newly committed code doesn't introduce problems.
Ensure issues are addressed before being merged.
Before to start
Before proceeding with creating a quality gate in your VCS for your repo, you must create a dedicated Code Reviews connection user for your project.
Enable Gating Code Reviews Settings
To automatically monitor your code with Code Reviews, you need to configure your Code Reviews Settings. You can configure your settings by navigating to the Code Reviews page, select the repository you’d like to enable gating on, then click the gear icon on the right:
In the Settings, navigate to Configuration and ensure the following settings are checked:
Enable Automated Code Reviews on PRs in tracked branches
Publish branch status checks on PRs
Publish a review on PRs in VCS
Allow Code Reviews to act as an approver on PRs
You must also have webhooks created. You can create a webhook by selecting the Create Webhook button.
If you have webhooks already created, your settings will look like this.
You can find out more information about the Code Reviews Settings on this Help Article.
Connection User
Bitbucket mandates that Pull Requests (PRs) receive approvals from a user distinct from the original author. To ensure the quality gate operates fully with Code Reviews, it is crucial to set up a dedicated connection user for Code Reviews within your project.
Setting up brach protection
In Bitbucket, hover over your project and click the
...menu that appears.Select
Settings.Under
Workflow, selectBranch restrictions.Click
Add a branch restriction.
Suggested Setup
Once you've added a branch restriction, select the Merge settings tab to configure your merge checks and conditions.
Under Merge checks, enable the following:
Minimum number of approvals: Set this to the total number of reviewers needed before a merge. For example, if you need two developers and Code reviews t to approve, set this to three.Minimum number of approvals from default reviewers: Use this to require sign-off from specific people, such as a team lead or architect.Minimum number of successful builds for the last commit with no failed builds and no in progress builds: Set this to match the number of active Code Reviews policies in your project. For example, if you have six active policies, set this to six.
Under Merge conditions, enable both:
Reset requested changes when the source branch is modified: Makes sure any new commits to the source branch trigger a fresh review, so stale approvals can't carry over.Prevent a merge with unresolved merge checks: Blocks merges until all checks pass, so no code can bypass your quality gate.
Click Save when done.
Bitbucket documentation
For more detail on configuring branch restrictions, see Bitbucket's own guides:



