Exit codes
A reference for the exit codes the SonarQube CLI returns, so you can integrate it into scripts, CI/CD jobs, and Git hooks.
The SonarQube CLI uses exit codes to signal what happened. Use them in scripts and your CI/CD environment to gate pipelines, fail builds, or run conditional checks.
0
Success. The command completed and (where applicable) found nothing to report. sonar remediate also exits 0 when the Remediation Agent is not eligible or not enabled for your organization (the CLI prints an informational message instead).
1
Command failure. Network error, authentication failure, server error, or any other unhandled problem.
2
Invalid options. You passed conflicting or unknown flags, or you omitted a required argument.
51
Findings or quality gate failure. sonar analyze secrets reports secrets, sonar analyze / sonar analyze agentic reports issues on the analyzed change set, or sonar quality-gate status reports a failed quality gate.
130
Interrupted. You pressed Ctrl+C while the CLI was running.
Note: Exit code 3 is not listed in this page's exit codes table. If you're seeing it, you're likely running
sonar-scanner(SonarScanner CLI) rather thansonar(SonarQube CLI). These are separate products. See the SonarScanner CLI docs for SonarQube Server or SonarQube Cloud.
How to use these in scripts
Treat findings as a failure
Because secrets and analysis findings exit with 51, fail a CI step automatically:
sonar analyze secrets src/
# Step fails if secrets are present (exit 51), passes otherwise.Distinguish "no findings" from "command broke"
If you want to keep going on findings but stop on real errors, branch on the exit code:
sonar analyze --staged
case $? in
0) echo "Clean, no new issues." ;;
51) echo "Issues found, but analysis succeeded." ;;
*) echo "Analysis failed (exit $?)."; exit 1 ;;
esacGate a CI step on quality gate status
sonar quality-gate status exits 51 when the quality gate fails, so a pipeline step fails automatically. When you omit --branch and --pull-request, the command auto-detects a pull request for the current git branch when SonarQube has analyzed exactly one matching pull request. If none matches, but your current branch has analysis in the project and is not the default branch, it reports that branch. Otherwise it reports the project's default branch. Pass --branch or --pull-request when the pipeline must check a specific scope. For a file or directory path, exit 51 means that path has failing conditions; exit 0 also covers a [· Not applicable] result (no conditions apply to the path). A path that cannot be resolved in the project tree exits 2.
Tolerate Ctrl+C cleanly
In long-running pipelines, treat 130 as a user-initiated cancel and avoid retrying:
Related pages
Last updated
Was this helpful?

