Chapter 11Lesson 04~115 minutes

Quality Gates, Conditions, Policies, and Pipeline Enforcement: Diagnostics, Failure Modes, and Production Practices

Diagnose misleading green pipelines, legacy-debt gate failures, small-change behavior, pull-request condition mismatches, and silent shared-gate edits with first-failure evidence intact.

DiagnosticsCI failureLegacy debtSmall changesAudit trail

Learning objectives

  • Diagnose scanner-success/gate-failure mismatches without rerunning blindly.
  • Detect thresholds changed after results were known and separate policy drift from code improvement.
  • Recognize when overall-code conditions turn inherited legacy debt into an unworkable release policy.
  • Explain small-change coverage behavior before treating an unexpected pass as a defect.
  • Identify pull-request conditions that cannot evaluate the same way as branch conditions.
  • Preserve gate definitions, task IDs, CI artifacts, and first-failure evidence before correction.

1. Diagnostic contract: preserve the first failure

Quality-gate troubleshooting starts by freezing the evidence that existed when the decision was made. Do not rerun the scanner, edit the gate, delete .scannerwork, or lower a threshold before saving the first task/result.

revision → scanner log → report-task.txt → ceTaskId → CE status → gate definition → project assignment → new-code setting → gate status → CI artifact

If those artifacts point to different runs, the diagnosis is already contaminated.

2. Evidence-first diagnostic ladder

  1. Preserve scanner, CI, API, and gate-definition evidence.
  2. Confirm SonarQube edition/version, scanner/runtime, instance mode, and integration versions.
  3. Confirm exact Git revision and effective analysis parameters.
  4. Inspect indexed-file/report evidence and ceTaskId.
  5. Wait for the matching Compute Engine task and inspect its status.
  6. Inspect project gate assignment, new-code definition, small-change setting, and actual failed condition values.
  7. Only then inspect auth/network/provider or server/database/search resource layers if the evidence points there.
  8. Apply the least destructive correction and rerun the smallest equivalent scenario.

3. Failure mode: scanner exit 0, server gate ERROR

This is the chapter’s intentionally broken example. A CI script assumes the scanner return code is the release decision:

# BROKEN POLICY
sonar-scanner -Dsonar.host.url="$SONAR_HOST_URL" -Dsonar.token="$SONAR_TOKEN"
echo "Quality passed; deploy now"

The scanner can exit successfully after upload while the matching background task later computes a failed gate. Prove the mismatch:

cat .scannerwork/report-task.txt
CE_TASK_ID=$(awk -F= '$1=="ceTaskId"{print $2}' .scannerwork/report-task.txt)
curl -fsS -H "Authorization: Bearer $SONAR_TOKEN" \
  "$SONAR_HOST_URL/api/ce/task?id=$CE_TASK_ID"
curl -fsS -H "Authorization: Bearer $SONAR_TOKEN" --get \
  --data-urlencode "projectKey=$PROJECT_KEY" \
  "$SONAR_HOST_URL/api/qualitygates/project_status"

If CE is SUCCESS and gate status is ERROR, the failure is not scanner execution. Repair the CI enforcement layer: use a supported provider quality check or sonar.qualitygate.wait=true. Do not change the project key or threshold.

4. Failure mode: choosing the threshold after seeing the result

A team gets 72% coverage and changes the gate from 80% to 70% that afternoon. The next pipeline is green, but the code did not improve. This is a policy change, not remediation.

Detect it by comparing gate definition/history, revision, and metrics. A legitimate threshold change must have independent rationale, representative impact analysis, approval, and rollback. If the only rationale is “the build was red,” reject the change as post-result tuning.

5. Failure mode: overall-code gate freezes a legacy system

A mature application with years of debt is assigned an overall maintainability/coverage threshold it cannot satisfy. Every unrelated patch fails. Teams respond by accepting issues, suppressing findings, or weakening gates.

The causal problem is policy population, not necessarily analyzer quality. Preserve the overall metrics, new-code metrics, NCD, and gate definition; then evaluate a new-code-focused gate plus a separately governed modernization objective. Do not erase old issues to obtain a green release.

6. Failure mode: “coverage is 0%, but the gate passed”

First inspect the denominator. Under the default small-change mechanism, a coverage condition can be ignored until there are enough new lines to cover. Capture:

  • new lines and new lines to cover;
  • coverage value;
  • the exact coverage condition;
  • the project/global “Ignore duplication and coverage on small changes” state;
  • the gate’s other condition results.

If the behavior matches the documented fudge factor, there is no defect to fix. Decide separately whether your organization wants a different small-change policy.

7. Failure mode: branch policy copied blindly into a pull request

Pull-request analysis is change-oriented and capability varies by deployment. A condition meaningful only for overall code should not be assumed to enforce identically in a PR. Community Build has narrower branch/PR support than commercial Server.

Diagnose by confirming edition, target branch, analysis type, applicable gate conditions, and provider decoration/check state. If the metric is unavailable in that context, move that control to a supported branch/release analysis or choose an appropriate new-code metric. Do not substitute a random metric just to keep one YAML template.

8. Failure mode: a shared gate changes silently

Two projects analyze unchanged revisions on different days and one unexpectedly flips status. Before blaming scanners, compare gate definition and project assignment timestamps. A shared gate edit can alter subsequent quality decisions across many projects.

Production practice: gate changes are configuration changes. Export/record the old definition, identify affected projects, review representative results, communicate the change, and retain an owner. “Someone with admin rights adjusted it” is not an acceptable audit trail.

9. Shortcuts that destroy diagnostic value

  • Do not rerun until the original report-task.txt and CI log are preserved.
  • Do not lower thresholds to “test” whether the gate is the problem.
  • Do not change project keys to escape history.
  • Do not use administrator tokens everywhere.
  • Do not disable TLS verification or auth to bypass a provider/network problem.
  • Do not edit the SonarQube database/search index directly.
  • Do not bulk-accept/suppress issues to make a gate green.

10. Production triage record

Question Required evidence
What revision/input was analyzed? Git SHA, effective parameters, coverage/external reports
Did scanner upload succeed? Scanner log and report-task metadata
Did server processing succeed? Matching CE task ID/status/error
Which gate applied? Gate name, conditions, assignment/default evidence
What population applied? New-code definition, branch/PR context, small-change setting
Why did the gate fail? Actual failed metric/operator/threshold/value
Why did CI allow/block delivery? Wait/check result and merge/release policy

Knowledge check

CE is SUCCESS but the gate is ERROR. Which layer failed?

What proves threshold gaming rather than code improvement?

Why should legacy debt not be erased to pass a gate?

What is the first check when low coverage on a tiny change still passes?

What should be preserved before rerunning a failed analysis?

Next lesson

Prove the entire operating model in one checkpoint

Lesson 5 repeats the two-run experiment as a formal evidence dossier with predictions, enforcement evidence, change-control metadata, rollback, and cleanup.

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.