How to block the merge of Pull Requests when SonarQube Quality Gate is failed, with Azure DevOps

This feature is available with Azure DevOps Service and Server 2019 as well as TFS 2015 and higher.

With Azure DevOps it’s possible to block the merge of a pull request if the SonarQube Quality Gate is failed on the PR (Pull Request).

This is called a Build policy in Azure DevOps, and can be defined per target branch, ie you can select which branches can accept pull request merges only if Quality Gate is passed. These branches are called protected branches

To do that:

  1. First Select the branch you want to protect with the passed Quality Gate build policy.
    Navigate to branches, and on the branch you want to protect, click on the vertical […] icon on the right.
    Select the Branch policies menu

  2. In the Branch policies screen click on Add build policy or Edit and existing build policy

  3. In the Edit build policy screen, select le Policy requirement Build must succeed in order to complete pull requests, and save

Once this is done, you’ll notice that any pull request to be merged on the protected branch can’t be merge if the Quality Gate on the Pull Request is Failed

See also:

That’s it folks !