SonarScanner exit code versus quality-gate status for pre-commit blocking
0 reputation · 24 Dec 2025, 02:34 UTC
Goal
Configure a repeatable pre-commit or CI gate that blocks commits when the SonarQube quality gate fails, using only the SonarScanner CLI and a shared sonar-project.properties file.
Constraints and uncertainty
The scanner returns exit code 0 for successful upload and analysis completion, while quality-gate pass or fail is evaluated server-side and must be queried separately. The property file does not encode the SonarQube server version, edition, or quality-profile version, so identical scanner invocations can yield different gate outcomes after a server upgrade. Project-level Execute Analysis permission is also required; a token lacking that permission causes the server to reject the analysis even when the property file is correct.
Questions
- What is the minimal CI integration pattern that reliably blocks on quality-gate failure without parsing scanner logs?
- How should the team version-pin or export the quality profile and server edition to keep the gate decision repeatable across scanner reinstalls?
- Which permission boundary must be verified for each developer token to ensure the pre-commit scan is accepted by the server?