Chapter 11Lesson 05~140 minutes

Checkpoint Lab — Quality Gates, Conditions, Policies, and Pipeline Enforcement

Produce a two-run quality-gate evidence packet that proves the gate definition, assignment, pass/fail analyses, CI enforcement behavior, rollback, and policy-change governance.

CheckpointPolicy dossierRollbackCI enforcementGovernance

Learning objectives

  • Execute a reproducible two-run pass/fail gate experiment from a clean local fixture.
  • Predict and verify at least two state changes before each analysis.
  • Prove the exact gate definition and project assignment used by every result.
  • Demonstrate asynchronous status inspection and explicit CI-style enforcement.
  • Document a policy-change process with ownership, rationale, impact review, and rollback.
  • Revoke lab credentials and verify cleanup without destroying retained evidence.

1. Checkpoint objective and acceptance criteria

Build an edition-aware quality-gate dossier that a reviewer can reconstruct without access to your shell history. You will prove one passing run, one failing run, the exact gate definition shared by both, the Compute Engine task behind each result, and the behavior of CI-style gate enforcement.

Success means: another engineer can answer “what was analyzed, under which policy, what did the server compute, why did it pass/fail, and what did CI do?” from the packet alone.

2. Record assumptions before touching policy

Date: 2026-09-07
SonarQube: Community Build 26.9.0.129388
Scanner: SonarScanner CLI 8.1.0.6389
Project: academy-sq-ch11
Gate: Academy Ch11 Coverage Gate
Condition: overall Coverage < 80.0% => fail
Token: project-analysis token; value never recorded
Commercial features: none required
CI/provider integration: none required; scanner wait simulates enforcement
Database/plugin/identity assumptions: inherited local lab server; no third-party plugin or IdP required

If your actual versions differ, replace these assumptions with observed values and re-check current documentation before executing the commands.

3. Preflight and guarded resources

  • Confirm SONAR_HOST_URL resolves only to your authorized lab instance.
  • Confirm the project/gate names are disposable and not used by other teams.
  • Confirm the gate is not the instance default.
  • Confirm your analysis token is project-scoped and can be revoked after the lab.
  • Confirm enough disk/memory exists for the already-running local SonarQube instance.
  • Create evidence/ outside any resource that a cleanup command will delete.
Abort conditions: stop if the host points to production, the gate name resolves to a shared standard, the project is not disposable, or the only available credential is an organization-wide administrator token.

4. Write predictions before Run A and Run B

State Run A prediction Run B prediction How verified
Git revision Pass fixture SHA Different SHA with untested code git rev-parse HEAD
Gate definition Coverage < 80 fails Unchanged UI/API gate evidence
Coverage report >=80% <80% Coverage XML + SonarQube measure
CE task Unique task, expected SUCCESS New unique task, expected SUCCESS ceTaskId + CE API/UI
Gate result OK ERROR Gate API/UI after matching CE completion
Default scanner command Success May still succeed after upload Captured return status
Wait-enabled scanner Success if gate OK Fails CI-style step on gate ERROR Captured wait-mode status/log

5. Execute the two-run experiment

Use the exact fixture and gate workflow from Lesson 2. Do not improvise new thresholds midway. For each run:

  1. Save revision SHA and sonar-project.properties.
  2. Generate and preserve coverage.xml.
  3. Run the scanner and preserve the full log.
  4. Copy .scannerwork/report-task.txt immediately.
  5. Extract and record ceTaskId.
  6. Wait for the matching CE task; record status/error if any.
  7. Record project coverage measure and gate result with failed-condition details.
  8. Record the project’s gate assignment and the gate definition again, proving policy did not change between runs.

6. Prove enforcement is a separate system state

At the failing revision, collect two CI-style outcomes:

# A. Default asynchronous behavior
set +e
sonar-scanner -Dsonar.host.url="$SONAR_HOST_URL" -Dsonar.token="$SONAR_TOKEN"
DEFAULT_RC=$?
set -e

# B. Explicit scanner-side gate enforcement
set +e
sonar-scanner \
  -Dsonar.host.url="$SONAR_HOST_URL" \
  -Dsonar.token="$SONAR_TOKEN" \
  -Dsonar.qualitygate.wait=true \
  -Dsonar.qualitygate.timeout=300
WAIT_RC=$?
set -e

printf 'default_rc=%s\nwait_rc=%s\n' "$DEFAULT_RC" "$WAIT_RC" \
  | tee evidence/ci-enforcement.txt

The packet must explain why these statuses can differ. If your CI/provider has a native SonarQube quality check, document that as the preferred production integration and keep this scanner-wait path as a local/free demonstration.

7. Required evidence packet

evidence/
├── assumptions.txt
├── gate-definition-before.json-or.md
├── project-gate-assignment.txt
├── pass-revision.txt
├── pass-coverage.xml
├── pass-scanner.log
├── pass-report-task.txt
├── pass-ce.json
├── pass-gate.json
├── fail-revision.txt
├── fail-coverage.xml
├── fail-scanner.log
├── fail-report-task.txt
├── fail-ce.json
├── fail-gate.json
├── ci-enforcement.txt
├── gate-definition-after.json-or.md
├── policy-change-record-template.md
└── cleanup-and-token-revocation.txt

Redact secrets. A token name/scope may be evidence; its value is not.

8. Write a policy-change record even though you are not changing production policy

Create a template that future operators can use:

Change ID:
Gate / projects affected:
Current condition(s):
Proposed condition(s):
Risk or business reason:
Why code remediation is insufficient:
Representative projects tested:
Predicted pass/fail changes:
Small-change and new-code implications:
Edition / metric availability assumptions:
Approver / owner:
Deployment date:
Verification:
Rollback trigger and procedure:
Review / expiry date:

This is the governance counterweight to “just lower the threshold.”

9. Cleanup and rollback

  1. Confirm all evidence is outside the SonarQube project and scanner working directory.
  2. Revoke the project-analysis token; record revocation time.
  3. If the gate was created solely for this checkpoint, unassign and delete only that exact custom gate after evidence is preserved.
  4. If the project was created solely for the lab, delete only academy-sq-ch11 after evidence is preserved.
  5. Delete the local fixture/venv only if you no longer need to reproduce the packet.
  6. Do not delete SonarQube volumes, database data, global scanner caches, or other projects as “cleanup.”

10. Verification checklist

  • □ Both revision SHAs are present and distinct.
  • □ Gate definition is identical across the pass/fail experiment.
  • □ Project assignment is proven.
  • □ Both scanner logs and report-task.txt files are preserved.
  • □ Each gate result is correlated to the correct ceTaskId.
  • □ Pass run shows coverage at/above threshold and gate OK.
  • □ Fail run shows coverage below threshold and gate ERROR.
  • □ Default scanner behavior is not mislabeled as gate enforcement.
  • □ Wait-enabled behavior is captured.
  • □ No credential value appears in the packet.
  • □ Cleanup/revocation is recorded.
  • □ Policy-change template contains owner, rationale, impact analysis, and rollback.

11. What Chapter 11 adds to a production operating model

After this checkpoint, a quality gate is no longer a colored badge. It is a versioned policy object connected to an explicit code population, an asynchronous analysis task, measurable conditions, a project assignment, and an enforcement mechanism.

The next chapter—New Code, Clean-as-You-Code, Baselines, and Legacy Modernization—takes the most important population in that model, “new code,” and makes its baseline and modernization consequences explicit.

Knowledge check

What must stay constant to make Run A versus Run B a valid gate experiment?

Why preserve gate definition both before and after?

What is the minimum evidence linking a scanner run to a gate result?

Why should a provider-native quality check be preferred when supported?

A threshold change has no owner or rollback plan. Is it governed?

What chapter concept must be understood next to interpret Sonar way correctly?

Next lesson — Next chapter

New Code, Clean-as-You-Code, Baselines, and Legacy Modernization

Chapter 12 defines what counts as new code, how baselines change the gate population, and how teams modernize legacy systems without hiding historical debt or blocking every future release.

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.