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.
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
-
Preserve scanner output and
report-task.txtif it exists. - Record SonarQube edition/version and scanner/JRE/plugin/integration versions involved.
- Record exact Git revision and dirty state.
- Reconstruct effective project key, host URL, base directory, source scope, and overrides.
- If upload occurred, follow the exact
ceTaskId. - Only after CE success inspect gate/profile/New Code/issues/measures.
- If CE fails, inspect database/search/JVM/host/container/plugin evidence.
- 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
-
Confirm the repository file says
academy-sonarqube-p06. -
Identify the higher-precedence
-Dsonar.projectKey. - Remove only that override.
- Rerun at the same Git revision with the same project token.
- 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
- Run the deliberate wrong-key command.
- Record whether failure occurs before or after report upload.
- Classify the failing layer before changing anything.
- Remove only the project-key override.
- Rerun at the same revision and compare evidence.
- Revoke the disposable token after completing the exercise.
Knowledge check
Why not replace a failing project token with an admin token?
It changes/widens the authorization model and can mask the real defect.
A CE task is FAILED. What should you inspect first?
The exact CE/background-task/server evidence, not the Quality Gate.
Why can command-line key contradict the project file?
Command-line scanner arguments have higher precedence.
Should you create a new project key to bypass identity errors?
No. Correct effective identity and preserve project history.
What is the minimum-rerun principle?
Keep unrelated inputs/revision constant, change one cause, and compare evidence.
Official references and version notes
- SonarQube downloads — current Community Build and Server release identities.
- Managing your tokens — user, project-analysis, and global-analysis token semantics.
- Analysis-parameter configuration overview — precedence and persistence.
- Managing JRE auto-provisioning and scanner environment requirements.
- SonarScanner CLI 8.1.0.6389 and official scanner metadata.
- Web API — bearer authentication and the gradual Web API V2 transition.
- CI integration overview — asynchronous processing and quality-gate waiting.
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.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this
address.