Blocking the merge of Pull Requests on failed Quality Gate, with Azure DevOps Services

The Azure Devops cloud offering as well as recent versions of Azure Devops Server were improved with tighter integration of PR Analysis Quality Gate status checks.
The guide for the configuration for Azure Devops Server 2019 and TFS 2015+ is still applicable.

This post thus describes the configuration steps needed to block the possibility to merge PRs after the Quality Gate for them failed:


To do that:

  1. Select the branch you want to protect by enforcing the Quality Gate check. Navigate to branches, on the branch you want to protect, click on the vertical […] icon on the right, and select the Branch Policies menu:

  2. In the Branch Policies screen, add a Status Check:

  3. Search and select SonarQube/quality gate, set it as Required and save:

You are all set!

Quick tips:

  • a pipeline is triggered on your PRs when Build Validation is set for the branch. Make sure you select it as well.
  • the Quality Gate status may show on Azure UI only after a first PR has been analyzed.