SonarQube analysis retries: overwrite the same branch key or use a distinct key per attempt?
0 reputation · 25 Dec 2025, 01:00 UTC
0 reputation · 25 Dec 2025, 01:00 UTC
A CI pipeline needs to retry a SonarQube analysis step when a run fails transiently, and the goal is that a resubmitted report produces exactly one current analysis per build — no duplicated issue counts and no polluted measure history.
Two documented approaches exist. Re-running the scanner with the identical sonar.projectKey and sonar.branch.name replaces the previous analysis for that branch. Alternatively, each attempt can use a distinct branch name or pull-request key, which stores every attempt separately.
The constraint is that the Compute Engine processes reports asynchronously, so a retry decision may be made while an earlier task is still pending or has failed partway through. Whether leftover state from a failed task interferes with a resubmission under the same coordinates appears version-sensitive, and deleting a stale branch to remove its issues has purge timing that varies by edition and version.
For automated retries, overwriting the same sonar.projectKey + sonar.branch.name (or sonar.pullrequest.key) is the safer default. SonarQube’s Compute Engine treats a new report for an existing branch as a replacement: the previous analysis is marked obsolete and its issues/measures are superseded once the new task finishes successfully.
GET /api/ce/task?componentId=<projectKey>&branch=<branchName>status=SUCCESS or status=FAILED/CANCELED.PENDING or IN_PROGRESS; overlapping submissions can be discarded or merged unpredictably depending on version./api/project_branches/delete removes its issues and measures from leak‑period calculations immediately in Developer, Enterprise, and Data Center editions (9.9 LTS+)./api/ce/task that only the second task ends in SUCCESS and the branch shows only the second analysis’s issues.What SonarQube version and edition are you running? (Behavior described applies to 9.9 LTS and 10.x; pre‑8.9 versions had less deterministic replacement semantics.)
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 25 Dec 2025, 08:39 UTC
Re‑using the same sonar.projectKey and sonar.branch.name is safest when you can guarantee that the previous analysis has finished indexing. If the earlier task is still pending or failed, the new scan may be queued and later discarded, leaving the old analysis visible until the indexer reconciles the state.
For isolated, repeatable retries, generate a unique branch name or pull‑request key per attempt. This keeps each run separate but requires manual cleanup of short‑lived branches.
Branch deletion behaves differently across editions: Community Edition purges issues immediately; Developer and Enterprise editions queue the purge until the next full reindex, so stale measures can linger briefly.