# Environment variables

{% hint style="warning" %}
This product is in Beta stage and breaking changes may be released. The documentation here matches the release version listed in the table of contents.&#x20;
{% endhint %}

Environment variables provide a non-interactive way to configure the SonarQube CLI without running `sonar auth login`. They are primarily used in CI/CD pipelines and automated environments where interactive authentication is not possible.

## Authentication

Set these variables to supply credentials directly. When the CLI finds a valid combination of authentication variables, it uses them immediately and skips any saved connection from `sonar auth login`.

| Variable               | Description                                                                                                                                                                                                                                      | Default                                                   |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------- |
| `SONARQUBE_CLI_TOKEN`  | Your user token. Required for environment variable authentication.                                                                                                                                                                               | -                                                         |
| `SONARQUBE_CLI_ORG`    | Your SonarQube Cloud organization key. Use together with `SONARQUBE_CLI_TOKEN` to authenticate with SonarQube Cloud.                                                                                                                             | -                                                         |
| `SONARQUBE_CLI_SERVER` | Your server URL. Use together with `SONARQUBE_CLI_TOKEN` to authenticate with SonarQube Server. For SonarQube Cloud, use together with `SONARQUBE_CLI_ORG` and set to `https://sonarcloud.io` (EU region) or `https://sonarqube.us` (US region). | `https://sonarcloud.io` (when `SONARQUBE_CLI_ORG` is set) |

Your `SONARQUBE_CLI_TOKEN` must be paired with either `SONARQUBE_CLI_ORG` or `SONARQUBE_CLI_SERVER`, or both, to connect:

* Authenticate with SonarQube Cloud, in the EU region: `SONARQUBE_CLI_TOKEN` + `SONARQUBE_CLI_ORG`
  * The default value,  `https://sonarcloud.io`, is applied to `SONARQUBE_CLI_SERVER`.<br>
* Authenticate with SonarQube Cloud in the US region: `SONARQUBE_CLI_TOKEN` + `SONARQUBE_CLI_ORG` + `SONARQUBE_CLI_SERVER`
  * Users must set `SONARQUBE_CLI_SERVER` to `https://sonarqube.us`.<br>
* Authenticate with SonarQube Server: `SONARQUBE_CLI_TOKEN` + `SONARQUBE_CLI_SERVER`
  * User must define the server URL to authenticate.<br>

If only one variable of a required pair is set, the CLI logs a warning and falls back to saved credentials.

{% hint style="info" %}
These variable names (`SONARQUBE_CLI_*`) are specific to the SonarQube CLI. The SonarQube MCP Server uses different names (`SONARQUBE_TOKEN`, `SONARQUBE_URL`, `SONARQUBE_ORG`).
{% endhint %}

### Examples

Authenticate with SonarQube Cloud:

```bash
export SONARQUBE_CLI_TOKEN=<YourUserToken>
export SONARQUBE_CLI_ORG=<YourOrganizationKey>
sonar list issues -p <YourProjectKey>
```

Authenticate with SonarQube Cloud in the [US region](https://app.gitbook.com/s/B4UT2GNiZKjtxFtcFAL7/getting-started/getting-started-in-us-region):

```bash
export SONARQUBE_CLI_TOKEN=<YourUserToken>
export SONARQUBE_CLI_ORG=<YourOrganizationKey>
export SONARQUBE_CLI_SERVER=https://sonarqube.us
sonar list issues -p <YourProjectKey>
```

Authenticate with SonarQube Server:

```bash
export SONARQUBE_CLI_TOKEN=<YourUserToken>
export SONARQUBE_CLI_SERVER=<YourSonarQubeURL>
sonar list issues -p <YourProjectKey>
```

## Related pages

* The list of SonarQube CLI [commands](https://docs.sonarsource.com/sonarqube-cli/using/commands "mention")
* The SonarQube CLI [quickstart-guide](https://docs.sonarsource.com/sonarqube-cli/quickstart-guide "mention")
