Chapter 11Lesson 01~100 minutes

Quality Gates, Conditions, Policies, and Pipeline Enforcement: Core Concepts and Mental Model

Learn how SonarQube turns completed analysis results into an explicit quality-policy decision, and why scanner success, Compute Engine success, gate status, and CI enforcement are different states.

Quality GateSonar wayCompute EngineNew codeCI policy

Learning objectives

  • Separate a quality-gate definition, project assignment, computed gate result, and CI decision.
  • Trace analysis upload through Compute Engine completion before treating any gate result as authoritative.
  • Explain the current Sonar way quality-gate conditions and why they focus on new code.
  • Distinguish scanner exit status from a server-side quality-gate pass or fail.
  • Inspect gate definitions and project status without changing shared policy.
  • Describe how instance mode, new-code definition, and small-change settings affect interpretation.

1. Current baseline and chapter boundary

A quality gate is not a scanner option that decides whether source code is “good.” It is a server-side policy evaluation performed after an analysis report has been accepted and processed. The scanner discovers and analyzes files, uploads a report, and records task metadata. SonarQube’s Compute Engine then processes that report, persists measures and findings, and evaluates the quality gate assigned to the project.

That ordering matters. A scanner process can finish successfully while the background task is still queued, and a background task can succeed while the resulting quality gate fails. A CI job becomes a release control only when it deliberately connects those states.

Policy boundary: do not edit a shared production gate, lower thresholds, disable the small-change mechanism, or reassign a production project merely to make a lab green. Every mutation in this chapter is confined to a disposable project and disposable custom gate.

2. The problem: a green command is not a release decision

Imagine a CI log that ends with EXECUTION SUCCESS. That means the scanner completed its own work and uploaded the analysis report. It does not, by itself, prove that Compute Engine processed the report successfully, that the project used the expected gate, that the gate passed, or that the CI provider enforced that result.

A trustworthy gate answers a narrower, auditable question: for this exact analyzed revision, under this exact gate definition and new-code policy, did the computed measures satisfy every applicable condition? A trustworthy pipeline then decides what to do with that answer.

3. Mental model: analysis result to delivery policy

Quality gate evaluation and enforcement path
flowchart TD
R[Repository revision] --> S[SonarScanner]
S --> AR[Analysis report]
AR --> CE[Compute Engine task]
CE --> M[Persisted measures and findings]
G[Assigned gate definition] --> E[Gate evaluator]
N[New-code definition] --> E
M --> E
E --> QS[Gate status: OK or ERROR]
QS --> UI[SonarQube UI/API]
QS --> CI[CI gate check or scanner wait]
CI --> D[Delivery decision]

The repository revision and effective scanner inputs identify what was analyzed. The analysis report is uploaded evidence, not the final gate. Compute Engine owns asynchronous processing. The assigned gate definition supplies metric/operator/threshold conditions. The new-code definition determines the population for conditions scoped to new code. The resulting gate status is then exposed to the UI/API and, only if configured, to CI enforcement.

4. Keep the gate states separate

State Owned by Evidence Common confusion
Gate definition Quality-standard administration Gate name, conditions, owners/permissions, change record Confused with the project’s last gate result
Project assignment Project/instance policy Default vs explicitly selected gate Assuming every project uses Sonar way
New-code definition Project/global analysis policy Previous version, days, specific analysis, or reference policy where supported Reading a “new coverage” threshold without knowing what counts as new
Analysis task Scanner + Compute Engine report-task.txt, ceTaskId, CE status/logs Treating upload success as analysis completion
Gate result SonarQube server OK/ERROR plus failed conditions and actual values Treating a stale prior result as the current run
CI decision CI/provider wait/check result, job status, protected-merge policy Assuming SonarQube automatically fails every pipeline

5. Current Sonar way: a read-only new-code gate

As of this chapter’s 2026-09-07 baseline, Community Build’s built-in Sonar way quality gate is read-only and is the default gate unless another gate is assigned. Its policy is intentionally new-code focused:

  • No new issues are introduced.
  • All new Security Hotspots are reviewed.
  • New-code test coverage is at least 80%.
  • New-code duplication is at most 3%.

The user-facing wording is stable, but the exact metrics behind “No new issues” depend on the instance mode. In MQR Mode and Standard Experience, issue/rating metrics differ. Record the instance mode and inspect the actual gate definition rather than copying condition keys from a different release or mode.

Why new code? Sonar way is designed to prevent newly introduced debt without requiring a team to remediate an entire inherited codebase before it can ship another change. Chapter 12 will go deeper into the new-code baseline itself.

6. Small changes and the quality-gate fudge factor

Coverage and duplication percentages can swing wildly on tiny diffs. Current Community Build therefore enables a quality-gate “fudge factor” by default: coverage conditions are ignored until there are at least 20 new lines to cover, and duplication conditions are ignored until there are at least 20 new lines. The setting is global by default and may be overridden for a project.

This is not permission to ignore small changes. Issue and hotspot conditions still matter, and the underlying coverage metric remains evidence. The operational lesson is to record whether sonar.qualitygate.ignoreSmallChanges or the corresponding UI setting is in force before diagnosing an unexpected pass.

7. Read-only inspection before policy changes

Start with state discovery. The UI is the least ambiguous way to see names and conditions; authenticated Web API calls are useful evidence when automation is needed.

export SONAR_HOST_URL="http://localhost:9000"
# Keep a real token in an environment/secret store. Do not paste it into HTML, source, or shell history.

# Server identity
curl -fsS "$SONAR_HOST_URL/api/server/version"

# Gate inventory (authentication requirements depend on instance security settings)
curl -fsS -H "Authorization: Bearer $SONAR_TOKEN" \
  "$SONAR_HOST_URL/api/qualitygates/list"

# Inspect the built-in gate without modifying it
curl -fsS -H "Authorization: Bearer $SONAR_TOKEN" --get \
  --data-urlencode "name=Sonar way" \
  "$SONAR_HOST_URL/api/qualitygates/show"

# After a project analysis, retrieve the project gate status
curl -fsS -H "Authorization: Bearer $SONAR_TOKEN" --get \
  --data-urlencode "projectKey=academy-sq-ch11" \
  "$SONAR_HOST_URL/api/qualitygates/project_status"

Record the raw response as evidence, but treat Web API paths as release-sensitive. The platform is gradually moving endpoints to Web API V2, so the instance’s own API documentation remains authoritative.

8. DevOps control: policy must be correlated to a task

A release gate is reproducible only if an auditor can connect revision → effective analysis inputs → report → ceTaskId → CE completion → assigned gate → gate status → CI decision. If any link is missing, “the gate failed” is an incomplete diagnosis.

This chapter therefore never uses gate color as standalone truth. Every later lesson preserves the gate definition and task identity alongside the result.

Knowledge check

The scanner exits 0. Has the quality gate necessarily passed?

What three policy inputs must be known before interpreting a new-code gate condition?

Why is Sonar way read-only?

What does the small-change mechanism affect?

Which component computes the authoritative gate result?

Next lesson

Turn the model into a controlled pass/fail experiment

Lesson 2 creates a disposable custom gate and project, generates a passing coverage analysis and a failing one, follows both Compute Engine tasks, and compares asynchronous scanner success with explicit quality-gate enforcement.

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.