Managing Quality Gates
Quality gates are defined at the organization level and applied at the project level. Each project has one quality gate assigned from among those defined in the organization.
Defining new quality gates for your organization
Every organization comes with the built-in Sonar way quality gate set as the default to be assigned to all new projects.
Though the Sonar way quality gate is suitable for most projects, there are cases where you may want to make adjustments. In those situations, you can create a new quality gate definition and either just make it available to projects in the organization or set it as the default for all new projects.
To create a new quality gate definition in an organization, you must be an administrator of that organization.
You can copy an existing quality gate, such as the Sonar way, and adjust it, or create an empty one and add conditions to it. The changes are made in Your Organization > Quality Gates.
In the example above we see two quality gates defined: the built-in one, called Sonar way, and another, custom-defined one, called Example QG.
A quality gate can have conditions on new code, conditions on overall code, both, or neither (though such an empty quality gate is not particularly useful, as it will always report a status of Passed).
Example QG, above, consists of six conditions on new code and five conditions on overall code.
Conditions can be added to either section by clicking Add Condition, adjusted by clicking the edit pen, and deleted by clicking the trash can.
Conditions define failure
Quality gate conditions are always stated in terms of failure. In other words, if any condition in the quality gate (in either new or overall code) is true, then the quality gate fails.
Deciding on a quality gate
For most cases, we recommend directly using or adapting the built-in Sonar way quality gate.
The Sonar way quality gate places a minimum requirement of an A rating on Reliability, Security and Maintainability, a minimum requirement of 50% Coverage and a maximum of 3% Duplicated Lines of code. This is applied to new code only. There are no conditions on overall code.
This quality gate represents our view of the best way to implement the Clean As You Code methodology, which we strongly recommend as the best way to get the most out of SonarCloud.
Some users may wish to add, remove or adjust the conditions (including adding some on overall code) using the Sonar way as a starting point.
The Add Condition button provides a selection of possible metrics for use in quality gate conditions. Keep in mind as you define your own quality gates, that the ultimate goal is to provide useful feedback to your developers when they look at the quality gate on their project page.
Setting the quality gate for your project
Once an organization administrator has made a new quality gate available in your organization, you can select that quality gate for use in your project.
To select a quality gate for a project, you must be an administrator of that project.
You select the quality gate that you want from the available ones listed in Your Organization > Your Project > Administration > Quality Gates:
If you don’t explicitly select a quality gate for your project, the default set for your organization will be selected by default. Usually, this is the Sonar way quality gate, though the organization administrator can change this default.