Latest
Sonar 1 min read

Set Up a SonarQube Quality Gate

Set Up a SonarQube Quality Gate
Sonar · July 11, 2026

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 quality gate is a group of pass-or-fail checks, such as a minimum test-coverage value. It helps a pipeline stop when a code change does not meet your chosen requirements.

Before you start

You need an existing SonarQube project, a successful first analysis, and permission to manage or assign a quality gate. Available conditions depend on your server version and edition.

Step 1: Choose the checks

Open Quality Gates in SonarQube. Start with the built-in gate or create a custom one. Rules decide which code issues are reported; the gate decides whether the reported results are acceptable. Keep the initial set small enough to understand.

Step 2: Assign the gate to the project

Assign the selected gate in the project settings. Check the new-code definition too: it determines which changed lines are measured. New-code coverage is not the same as coverage across the whole project.

Step 3: Make the pipeline wait

Run the scanner with these options:

sonar-scanner \
  -Dsonar.qualitygate.wait=true \
  -Dsonar.qualitygate.timeout=300

A failed gate or a timeout must leave the job failed. Do not add || true or a setting that ignores the job result.

Step 4: Try a failing change

On a test branch, make a small change that fails one configured condition. Run analysis and verify that the job fails for that condition. Require the job in your repository’s merge rules. A failed job does not block a merge unless those rules enforce it.

Check the result

Try a passing change as well. The SonarQube gate and the pipeline status should agree. Check scanner errors separately: a failed scan is not a quality-gate decision.

References

PB
Written by

Parul Bedi

Notes and guides by Parul Bedi.

Up next

Choose What SonarQube Treats as New Code

Sonar July 19, 2026 1 min read
Open post

Conversation

0 comments

No comments yet. Start the conversation below.

Leave a comment

Replying to a comment.
Be kind. Markdown is not supported in comments.