Checkpoint Lab — New Code, Clean-as-You-Code, Baselines, and Legacy Modernization
Modernize a disposable legacy sample under a stable new-code policy and produce an evidence packet proving the baseline, new/overall populations, gate results, policy-change experiment, rollback, and governance rationale.
Learning objectives
- Execute a complete baseline → change → definition experiment → rollback workflow in a disposable Community Build project.
- Predict and independently verify source, baseline, measure, gate, and credential state changes.
- Prove the same source revision can yield a different new-code population when policy changes.
- Document why the governed baseline is retained even when another definition produces a greener result.
- Retain an evidence packet while revoking credentials and deleting only guarded lab resources.
- Connect New Code governance to the metrics and measure semantics introduced in Chapter 13.
1. Checkpoint scenario
You own a deliberately imperfect legacy service. Your task is to demonstrate that a stable New Code policy can let new work meet a modern standard while legacy risk remains visible. Then you will alter only the baseline definition, prove the resulting measurement change, restore the approved baseline, and document why the greener-looking alternative is not automatically the better policy.
- Baseline and final Git revision manifests.
- Exact Community Build/scanner/runtime assumptions.
- New Code definition before, during, and after the experiment.
-
Analysis keys/build strings and
report-task.txt/ceTaskIdevidence. - Overall and new coverage/issue/gate evidence.
- SCM/history evidence.
- Baseline-change control note plus legacy-risk note.
- Credential revocation and guarded cleanup evidence.
2. Resource and credential preflight
- □ Local SonarQube Community Build 26.9.0.129388 is healthy.
- □ SonarScanner CLI 8.1.0.6389 is recorded.
- □ Python 3.11+ and Git are recorded.
- □ The repository is full-depth and not shallow.
-
□
academy-sq-ch12is disposable and uniquely identified. - □ Scanner uses a project-analysis token; policy mutation uses a separate temporary admin credential.
- □ No production source, user identity, database, CI provider, cluster, or credential is involved.
git rev-parse --is-shallow-repository
git rev-parse HEAD
sonar-scanner --version
python --version
curl -fsS "$SONAR_HOST_URL/api/server/version"
3. Write predictions before execution
| Action | Predicted state change | Independent proof |
|---|---|---|
| Set Specific analysis baseline | Project New Code policy references baseline analysis key; source unchanged | api/new_code_periods/show + Git SHA |
| Add tested checkout module | Git revision changes; New Code expands; legacy overall state remains | Git diff + scanner logs + new/overall measures |
| Switch to one-day window | Source SHA unchanged; New Code population expands to same-day legacy lines | Definition JSON + same SHA + new/overall measures |
| Restore Specific analysis | Source unchanged; population returns to governed baseline | Definition JSON + rerun task + measures/gate |
| Revoke tokens | Credentials can no longer authenticate | Revocation record / expected unauthorized response |
4. Execute the controlled modernization workflow
Use the exact fixture and commands from Lesson 2 or reproduce an equivalent fixture whose legacy baseline is demonstrably imperfect and whose new slice is thoroughly tested. Keep these invariants:
-
Baseline analysis is identified by
sonar.buildStringand analysis key. - Specific analysis points to that exact approved baseline.
- New source has enough coverable lines to avoid a trivial small-change interpretation.
- The definition experiment reruns the same Git SHA.
- The gate/profile/scanner/server stay fixed during the definition-only experiment.
- The final state restores the Specific analysis baseline.
5. Build the evidence packet
evidence/
assumptions.txt
baseline-revision.txt
baseline-coverage.xml
baseline-report-task.txt
project-analyses.json
new-code-specific-baseline.json
change-revision.txt
change-coverage.xml
change-report-task.txt
measures-specific-baseline.json
gate-specific-baseline.json
definition-experiment-revision.txt
new-code-one-day.json
one-day-report-task.txt
measures-one-day.json
gate-one-day.json
new-code-restored.json
restored-report-task.txt
measures-restored.json
gate-restored.json
scanner-versions.txt
scm-state.txt
baseline-change-control.md
legacy-risk-note.md
cleanup.txt
Do not store token values. If a raw log includes authorization material or local secrets, redact a copy while retaining the sensitive original only in an appropriately protected lab location—or avoid collecting that field entirely.
6. Verification checklist
- □ Baseline analysis key maps to the baseline revision/build string.
- □ Specific analysis definition references that key.
- □ Change revision differs from baseline revision.
- □ Overall coverage remains materially lower than new coverage under the approved baseline.
- □ Definition-only experiment uses exactly the same source SHA as the preceding run.
- □ One-day definition and restored definition responses are preserved.
-
□ Every scanner run is correlated to a
ceTaskIdand CE completion. - □ Gate results are recorded after CE completion, not inferred from scanner exit status.
- □ Full SCM state is proven.
- □ No source or policy was silently changed to force expected numbers.
- □ Final policy is the approved governed baseline.
7. Baseline-change control note
# New Code baseline change control
Project: academy-sq-ch12
Current approved definition: SPECIFIC_ANALYSIS
Approved analysis key / revision:
Experiment definition: NUMBER_OF_DAYS / 1
Source SHA during experiment:
Reason for experiment: demonstrate population sensitivity only
Observed impact on new-code measures/gate:
Impact on legacy-risk visibility:
Why experiment definition is or is not suitable for production:
Approver / owner:
Rollback: restore approved SPECIFIC_ANALYSIS key
Verification after rollback:
Review / expiry: immediate after lab
The note must explain the policy using delivery semantics, not “this setting is greener.”
8. Legacy-risk note
Record at least one inherited quality gap from the fixture—such as low overall coverage—and state what the new-code gate does and does not address. In a real system, this note would also list severe vulnerabilities, reliability defects, regulatory issues, ownership, target dates, and compensating controls.
9. Guarded cleanup and rollback
- Confirm the approved New Code definition is restored.
- Copy evidence outside
.scannerwork. - Revoke the project-analysis token and temporary admin token; record the time.
- Delete the disposable project only if it was created solely for the checkpoint and evidence is already preserved.
- Delete the local fixture/virtual environment only when reproduction is no longer needed.
- Do not delete SonarQube database/search state, Docker volumes, global caches, unrelated projects, or shared quality policy as cleanup.
10. What Chapter 12 adds to a governed production operating model
After this checkpoint, “new code” is no longer an unexplained dashboard filter. It is a versioned policy boundary linked to a definition/reference, revision/SCM state, analysis task, measures, gate results, and an explicit modernization strategy.
The organization can now say both: “we are not adding new debt” and “we still own this inherited debt.” Chapter 13—Metrics: Reliability, Maintainability, Security, Complexity, and Size—builds on that foundation by defining exactly what the resulting measures mean and where metric interpretation can go wrong.
Knowledge check
What is the strongest evidence that the definition—not source—caused a metric change?
The same Git SHA/scanner inputs produce different new-code measures under two recorded definitions, with matching task evidence.
Why must overall metrics stay in the checkpoint packet?
Because Clean-as-You-Code governs recent changes but does not erase inherited debt; overall measures retain modernization context.
What would invalidate the baseline experiment?
Changing source, gate/profile, scanner/server version, or other material analysis inputs at the same time as the definition.
Why is the baseline analysis key more useful than a screenshot alone?
It identifies the exact analysis object used by Specific analysis and can be correlated to revision/build metadata programmatically.
A legacy vulnerability is outside New Code. What should happen?
It remains governed through the appropriate security/risk process; new-code scope is not a waiver for severe historical risk.
What is the next analytical skill after baseline governance?
Interpreting SonarQube metrics—reliability, maintainability, security, complexity, size, and their new/overall variants—without turning them into misleading scores.
Official references and version notes
- Quality standards and new code — current New Code concepts, four definition modes, default baseline, and Clean-as-You-Code framing.
- Configuring new code calculation — project overrides, Specific analysis API-only behavior, and Previous version configuration.
- Global New Code baseline — global inheritance and the default Previous version baseline.
- Checked-out code — full Git history requirements for New Code, blame, and issue backdating.
- Issue management solution — issue identity/date/backdating and how current analysis relates findings to new code.
- Understanding quality gates — Sonar way and new-code-focused quality conditions.
- Feature comparison table — current Community Build versus Server/Cloud branch and pull-request boundaries.
- Analysis overview — scanner/report/Compute Engine processing and new/overall result computation.
- Web API — authenticated API usage and release-sensitive endpoint guidance.
- SonarQube downloads — current Community Build release identity.
- SonarScanner CLI 8.1.0.6389 — scanner baseline used by the local lab.
Rechecked 2026-09-07. Mandatory executable examples target SonarQube Community Build 26.9.0.129388 and SonarScanner CLI 8.1.0.6389. Current Community Build documentation lists Previous version, Number of days, Specific analysis, and Reference branch as New Code definition modes; the project-level definition overrides the global baseline, whose default is Previous version. Specific analysis is configured through the Web API. Commercial branch analysis and broader enterprise capabilities are not required by this chapter. Re-check the linked primary documentation and your instance’s built-in Web API before automating against 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.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this
address.