Chapter 06Lesson 04~130 minutes

Projects, Tokens, Scanners, Analysis Parameters, and First Analysis: Diagnostics, Failure Modes, and Production Practices

Diagnose first-analysis failures by preserving scanner/task evidence and isolating configuration, authorization, upload, Compute Engine, policy, and infrastructure layers.

DiagnosticsAuthorizationPrecedence driftCE taskEvidence

Learning objectives

  • Apply an evidence-first diagnostic sequence before retrying.
  • Diagnose a deliberate higher-precedence project-key override.
  • Separate scanner, upload, CE, gate, and CI failure semantics.
  • Avoid admin-token escalation, direct DB/search edits, blanket restarts, and policy lowering.
  • Rerun the smallest equivalent scenario after changing one cause.

1. A red job is only a symptom

Layer Symptom First evidence
Source/workspace Wrong/missing files or revision Git status/revision + indexing log
Parameters/base directory No files or wrong project config + invocation + effective base/key
Auth/permissions 401/403 / not authorized token type/project/issuer permissions/expiry
Scanner/runtime/network bootstrap/JRE/TLS/connection error scanner/JRE version + connectivity log
Report/CE upload succeeds but dashboard absent/failed report-task.txt + CE task
Policy CE succeeds but gate red gate conditions/New Code/profile
Infrastructure CE/search/database instability server health + web/ce/es logs/resources

2. Evidence-first diagnostic sequence

  1. Preserve scanner output and report-task.txt if it exists.
  2. Record SonarQube edition/version and scanner/JRE/plugin/integration versions involved.
  3. Record exact Git revision and dirty state.
  4. Reconstruct effective project key, host URL, base directory, source scope, and overrides.
  5. If upload occurred, follow the exact ceTaskId.
  6. Only after CE success inspect gate/profile/New Code/issues/measures.
  7. If CE fails, inspect database/search/JVM/host/container/plugin evidence.
  8. Change one suspected cause and rerun the same source/configuration otherwise.

3. Intentionally broken example: wrong command-line key

The project file has the correct key and the token is scoped to it. Run this only against the disposable lab:

sonar-scanner -Dsonar.host.url="$SONAR_HOST_URL"   -Dsonar.projectKey=academy-sonarqube-p06-other

The command-line key overrides the file. The scoped token should not gain authority over another project. The exact error depends on project existence and permissions, so preserve it. Do not “fix” this by switching to an administrator token.

4. Repair the cause, not the permission model

  1. Confirm the repository file says academy-sonarqube-p06.
  2. Identify the higher-precedence -Dsonar.projectKey.
  3. Remove only that override.
  4. Rerun at the same Git revision with the same project token.
  5. Compare project identity, indexing, report/task evidence, and outcome.

5. Keep five statuses separate

  • Scanner process success — client execution completed.
  • Report upload — server accepted report and created CE work.
  • CE task success — server processed/persisted analysis.
  • Quality Gate pass — completed analysis satisfies policy.
  • CI job pass — pipeline logic decided to pass; it may or may not wait for gate.

A gate failure is not a scanner defect. A scanner failure before upload is not a quality-policy failure.

6. Wrong base directory / indexed-file set

If the scanner starts from the wrong directory, relative configuration and sources can resolve incorrectly. Diagnose from the scanner-reported base directory and indexing evidence. Do not compensate with broad inclusions until you understand why the base/scope is wrong. Chapter 08 expands this into full indexing/SCM diagnostics.

7. Token failures without escalation

Inspect token type, associated project, author Execute Analysis permission, expiration/revocation, and target server. Never commit the token, disable authentication, log it for debugging, edit permission rows directly in the database, or use an admin token merely to make the error disappear.

8. CE/server failure

If upload produced a task ID and the task fails, preserve that task and inspect Background Tasks / ce.log. Database outages, search failures, incompatible plugins, malformed reports, or resource pressure belong to server-side diagnosis. Direct database/search edits are unsupported shortcuts and can damage consistency.

9. Evidence-destroying shortcuts

Shortcut Problem Safer action
Restart everything Destroys timing/context and may hide owner Preserve evidence; restart only implicated disposable component
Delete .scannerwork immediately Removes client/task bridge Copy metadata/log first
Use admin token Masks scope/permission defect Fix least-privilege token/permission
Lower gate threshold Changes policy to hide result Keep policy; diagnose condition/data
Use a new project key Abandons history and hides identity drift Correct the effective key

10. Failure-analysis lab

  1. Run the deliberate wrong-key command.
  2. Record whether failure occurs before or after report upload.
  3. Classify the failing layer before changing anything.
  4. Remove only the project-key override.
  5. Rerun at the same revision and compare evidence.
  6. Revoke the disposable token after completing the exercise.

Knowledge check

Why not replace a failing project token with an admin token?

A CE task is FAILED. What should you inspect first?

Why can command-line key contradict the project file?

Should you create a new project key to bypass identity errors?

What is the minimum-rerun principle?

Next lesson

Prove the complete first-analysis operating contract

Lesson 5 builds an evidence packet covering revision, parameters, token scope, scanner metadata, CE result, gate, revocation, limitations, and guarded cleanup.

Official references and version notes

Version and compatibility note

Rechecked on 2026-09-07. Mandatory examples target local/private Community Build 26.9.0.129388 and standalone SonarScanner CLI 8.1.0.6389. JRE auto-provisioning is supported by current Scanner CLI and is enabled by default unless deliberately disabled; when disabled, use the current documented scanner Java requirement rather than legacy guidance. No commercial edition, branch/PR analysis, third-party plugin, IDE connected mode, CI provider, managed database, or cloud account is required.

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.