Chapter 11Lesson 03~105 minutes

Quality Gates, Conditions, Policies, and Pipeline Enforcement: Configuration, Design Patterns, and Trade-Offs

Choose between Sonar way and custom gates, new-code and overall conditions, advisory and enforced policy, and centralized standards versus governed exceptions.

Custom gatesFudge factorPull requestsGovernanceTrade-offs

Learning objectives

  • Choose when Sonar way is preferable to a custom gate and when a custom gate is justified.
  • Explain the operational difference between new-code conditions and overall-code conditions.
  • Compare advisory dashboards, scanner wait enforcement, and provider-native quality checks.
  • Account for the quality-gate fudge factor on small coverage and duplication changes.
  • Treat pull-request behavior and commercial capabilities as explicit edition boundaries.
  • Design a governed exception and change process for centralized quality policy.

1. Design goal: one quality policy, several enforcement contexts

The Chapter 11 lab used an intentionally simple overall-coverage gate because it was easy to control. Production gate design is different: policy must survive changing repositories, teams, CI providers, analyzer versions, and inherited legacy code without encouraging developers to game metrics.

A gate therefore needs an owner, rationale, target code population, metric semantics, enforcement location, and change process—not just thresholds.

2. Sonar way versus a custom gate

Choice Strength Risk Evidence before choosing
Sonar way Read-only, maintained recommended standard, new-code focused May not express a justified domain-specific requirement Actual built-in conditions, instance mode, team release policy
Custom gate copied/from scratch Can add project/domain requirements Drift, threshold gaming, stale metrics after upgrades Owner, reason, affected projects, version review cadence
One central custom gate Consistency and simpler audit May be inappropriate across very different technologies Portfolio of project types and metric availability
Several governed gates Supports legitimate technical differences Policy sprawl and exception-by-default Explicit decision matrix and approval ownership

Do not fork Sonar way merely to rename it. Create custom policy only when you can explain what additional risk is being controlled and who owns future updates.

3. New-code conditions versus overall-code conditions

New-code conditions answer whether the current change meets today’s standard. Overall conditions answer whether the entire current codebase meets a threshold. Both can be valid, but they solve different governance problems.

new-code gate → prevent introduction of new debt
overall gate → enforce an estate-wide property or modernization milestone

A harsh overall condition applied to a large inherited codebase can block every release for historical debt unrelated to the change. If an organization needs an overall target, pair it with a measured modernization program rather than silently converting legacy debt into an emergency release blocker.

4. Advisory dashboard versus pipeline enforcement

Mode How it works Best use Failure mode
Dashboard/advisory SonarQube computes gate; CI does not block Rollout, observation, policy calibration Teams ignore persistent red status
Scanner wait sonar.qualitygate.wait=true polls and fails analysis step Generic CI without a native asynchronous check Consumes CI worker while waiting; timeout must be understood
Provider-native gate/check CI/provider receives SonarQube quality status asynchronously Supported DevOps integrations Provider check misconfigured or not required by merge policy
Manual release review Human verifies recorded gate evidence Highly controlled or exceptional release process Unrecorded overrides become normal behavior

“Enforced” means the delivery system actually prevents the undesired action. A red SonarQube badge that nobody checks is informative, not enforcement.

5. Small-change policy is an explicit semantic, not a hidden exception

The default quality-gate fudge factor ignores coverage and duplication conditions until the new-code population reaches the documented minimum. Keep it enabled unless you have a reason to change it, and record any project override. If a five-line change passes despite low percentage coverage, first inspect the number of new lines to cover and the small-change setting before assuming the gate is broken.

Disabling the mechanism can be reasonable for a codebase with very dense critical changes, but it creates volatile percentages on tiny diffs. Treat that as a governance choice with test evidence, not a cosmetic setting.

6. Pull-request behavior and edition boundaries

Community Build and commercial SonarQube Server do not expose identical branch/PR capabilities. The current feature matrix should be checked before designing provider policy. Community Build supports main-branch analysis and a narrower pull-request case; commercial Server adds broader branch/PR capabilities.

Where pull-request analysis is available, quality-gate computation is change-oriented: conditions applying to new code are the meaningful conditions for a pull request, and overall-code conditions should not be assumed to drive the PR result. A policy that depends on an overall metric must therefore be enforced on a branch/release analysis or redesigned around a new-code metric where appropriate.

Do not fake unavailable PR metrics. If a metric is not computed for the analysis type, do not substitute a different metric merely to keep a pipeline script generic. Make the edition/analysis boundary explicit.

7. Centralized standards and project-specific exceptions

Central policy is valuable because a threshold means the same thing across teams. Exceptions are sometimes legitimate—for example, generated migration code, a special test-only repository, or a staged modernization program—but every exception should carry:

  • owner and approver;
  • scope: project/gate/condition;
  • technical rationale;
  • start date and review/expiry condition;
  • before/after impact evidence;
  • rollback path.

If a project silently chooses a weaker gate with no expiry or owner, that is policy drift rather than governance.

8. Gate changes are production configuration changes

  1. Export or record the current gate definition and associated projects.
  2. State the risk/problem the proposed change solves.
  3. Test the proposed condition against representative historical/project data.
  4. Review unintended pass/fail changes, including different languages and new-code sizes.
  5. Approve through the organization’s configuration-change process.
  6. Change the gate with least privilege.
  7. Reanalyze representative projects and retain result evidence.
  8. Monitor and roll back if outcomes differ from the prediction.

9. Worked decision table

Scenario Recommended pattern Why Verification
New service with normal risk profile Sonar way + enforced CI check Strong maintained new-code standard with minimal local drift Gate definition, NCD, provider/check required state
Large legacy application New-code gate + separate modernization metrics Blocks new debt without freezing releases on historic debt New-code baseline and legacy-debt trend
Safety-critical library needing stricter coverage Governed custom gate Domain rationale justifies stronger threshold Owner, threshold study, representative runs
Tiny project with frequent 3-line changes Keep small-change behavior unless evidence says otherwise Avoid percentage volatility from tiny denominators New lines to cover, ignored-condition evidence
PR check in unsupported analysis/edition path Use supported branch/main analysis or upgrade/simulate Do not invent unavailable PR semantics Feature matrix and actual CI integration

Knowledge check

Why is a new-code gate usually safer for a legacy codebase?

Is a red SonarQube gate automatically enforced?

What should precede a custom gate?

Why can a small change bypass a coverage condition by design?

What is the safer response when a PR cannot compute a metric used by an overall gate?

Next lesson

Diagnose gate failures without changing the evidence

Lesson 4 applies the model to misleading green scanners, legacy-debt blockers, small-change surprises, pull-request mismatches, and silent shared-gate edits.

Official references and version notes

Version and compatibility note

Rechecked 2026-09-07. Mandatory executable examples target SonarQube Community Build 26.9.0.129388 and SonarScanner CLI 8.1.0.6389. Current commercial reference points are SonarQube Server 2026 Release 4.1 and 2026 Release 1.5 LTA; no commercial feature is required. Sonar way, supported gate metrics, pull-request behavior, CI integrations, Web API surfaces, and defaults can evolve, so re-check the linked primary documentation before applying these examples to another release.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.