# Exit codes

> **Warning:** This product is in Beta stage and we may release breaking changes. The documentation here matches the release version listed in the table of contents.

The SonarQube CLI uses exit codes to signal what happened. Use them in scripts and CI/CD to gate pipelines, fail builds, or branch logic.

| Code  | Meaning                                                                                                                                   |
| ----- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `0`   | Success. The command completed and (where applicable) found nothing to report.                                                            |
| `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. `sonar analyze secrets` reports secrets, or `sonar analyze agentic` / `sonar verify` reports issues on the analyzed change set. |
| `130` | Interrupted. You pressed `Ctrl+C` while the CLI was running.                                                                              |

## How to use these in scripts

### Treat findings as a failure

Because secrets and analysis findings exit with `51`, fail a CI step automatically:

```bash
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:

```bash
sonar verify --staged
case $? in
  0)   echo "Clean — no new issues." ;;
  51)  echo "Issues found, but analysis succeeded." ;;
  *)   echo "Analysis failed (exit $?)."; exit 1 ;;
esac
```

### Tolerate `Ctrl+C` cleanly

In long-running pipelines, treat `130` as a user-initiated cancel and avoid retrying:

```bash
sonar verify
rc=$?
if [ "$rc" -eq 130 ]; then
  echo "Cancelled."; exit 130
fi
```

## Related pages <a href="#related-pages" id="related-pages"></a>

* [Commands reference](/sonarqube-cli/using-sonarqube-cli/commands.md)
* [Environment variables](/sonarqube-cli/using-sonarqube-cli/environment-variables.md)
* [Output formats](/sonarqube-cli/using-sonarqube-cli/output-formats.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-cli/using-sonarqube-cli/exit-codes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
