Version note: references describe SonarQube Server 2025.2 behaviour. Check your server, scanner and edition requirements. These examples were not run against a live SonarQube server.
What this guide covers
A scanner can finish uploading before SonarQube finishes processing. Waiting for the quality gate prevents a pipeline from reporting success while the server result is still unknown.
Before you start
Use a working analysis job. The job must be able to reach SonarQube until processing completes. Pick a timeout long enough for normal queue time, with a separate overall job timeout.
Step 1: Enable the wait option
Add these properties to the scanner configuration, or pass them as -D arguments:
sonar.qualitygate.wait=true
sonar.qualitygate.timeout=300
The scanner waits up to 300 seconds. Increase that value only after checking normal processing time.
Step 2: Keep errors visible
Do not ignore the scanner exit code. A failed analysis, failed gate and timeout should not silently become a successful job. A timeout means the decision is unknown; it does not mean the code passed.
Step 3: Use the current analysis if you query the API
Prefer the scanner’s supported wait behavior. If a custom integration must query the API, follow this sequence:
.scannerwork/report-task.txt -> ceTaskId
GET /api/ce/task?id=TASK_ID -> task status and, on success, analysisId
GET /api/qualitygates/project_status?analysisId=ANALYSIS_ID -> gate decision
Wait until the compute task succeeds before using its analysisId. Querying the project’s latest result can return another build’s result.
Step 4: Test passing and failing jobs
Use a test branch to confirm a failed condition fails the job. Also check server unavailability and timeout handling. Require the job in merge or deployment rules if it must block those actions.
Check the result
The pipeline decision should match its own completed analysis, not an earlier scan. Keep quality-gate approval separate from other tests and release requirements.
Conversation
0 commentsNo comments yet. Start the conversation below.