> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/internal-developer-portal/use-idp/plugins/available-plugins/sonarqube.md).

# SonarQube

| Plugin details |                                                                                                                            |
| -------------- | -------------------------------------------------------------------------------------------------------------------------- |
| **Created by** | [SDA SE](https://sda.se/)                                                                                                  |
| **Category**   | Quality                                                                                                                    |
| **Source**     | [GitHub](https://github.com/backstage/community-plugins/tree/main/workspaces/sonarqube/plugins/sonarqube#sonarqube-plugin) |
| **Type**       | Open-source plugin                                                                                                         |

### Configuration <a href="#configuration" id="configuration"></a>

#### Application configuration YAML <a href="#application-configuration-yaml" id="application-configuration-yaml"></a>

* Under the **Plugins** tab in **Configure**, go to `app-config.yaml` and **Edit YAML** to configure your SonarQube instance in the **target** field.

![](/files/pfAmtsrHRVXjl1m4rlBb)

#### Secrets <a href="#secrets" id="secrets"></a>

* Go to SonarQube, "eg: `https://sonar.your-comapny-name.io/account/security`", for generating a new token, **Enter Token Name** and choose **User Token** in **Select Token Type**.
* Ensure the secret is *not* encoded. Harness will handle the encoding of the secret and passing it to the destination.

{% hint style="info" %}
Ensure that the user creating the token has the necessary permissions to access the specified instance and project mentioned in the [annotations](#annotations). Additional troubleshooting information can be found [here](#troubleshooting).
{% endhint %}

![](/files/9Y1Oko6uozeMdGZPhq00)

* **Create secret in Harness** to store API token, click on “New Secret Text” and enter values as shown below.

![](/files/noBBknJxGoH8IJuhXcZe)

#### Delegate proxy <a href="#delegate-proxy" id="delegate-proxy"></a>

* If SonarQube is deployed on-prem, `sonar.mycompany.com` will not be accessible from outside, so a delegate proxy has to be selected. Ensure you have [Harness Delegate installed](/harness-ai/use-harness-platform/delegates/delegate/install-delegates/overview.md) for the same.

![](/files/ay7P4CwvVz3eSPJdNBDy)

### Layout <a href="#layout" id="layout"></a>

This plugin exports a UI card that you can show on the **Overview** tab of a service or any other layout page. The following configuration is set by default in **Layout** under **Configure** for **Service** and you do not need to change anything:

```yaml
- component: EntitySonarQubeCard
          specs:
            gridProps:
              md: 6
```

![](/files/vlCPLzNTCBXimlX1cvK3)

### Annotations <a href="#annotations" id="annotations"></a>

To configure the plugin for a service in the software catalog, set one of the following annotations in its `catalog-info.yaml` definition file.

The following configuration is recommended:

```yaml
metadata:
  annotations:
    sonarqube.org/project-key: <instance-name>/<project-key>
```

The `instance-name` is optional if there is only one SonarQube instance, as the default instance from the plugin configuration will be used.

[Read more](https://github.com/backstage/community-plugins/tree/main/workspaces/sonarqube/plugins/sonarqube#sonarqube-plugin)

### Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

#### 401 Unauthorized <a href="#id-401-unauthorized" id="id-401-unauthorized"></a>

* Check for the validity of the user token added as secrets.
* Ensure that the user token you have used has access permission to the instance mentioned in the annotation.

#### There is no SonarQube project with key <a href="#there-is-no-sonarqube-project-with-key" id="there-is-no-sonarqube-project-with-key"></a>

* We need to use the `project_id`, **not** the project name. The `project_id` can be found in the URL, where it appears as `?id=project-id`
* The SonarQube token configured in the Harness secret no longer needs to be encoded as of IDP service 1.29.

Previous versions required a **base64** encoded token.

* Ensure that the user token you have used has the permission to view the project mentioned in the annotation.
* The `sonarqube.org/project-key` annotation is of the correct format `<instance-name>/<project-key>`.

### Support <a href="#support" id="support"></a>

The plugin is owned by SDA SE and managed in the [Backstage repository](https://github.com/backstage/community-plugins/tree/main/workspaces/sonarqube/plugins) as an open-source project. Create a GitHub issue to report bugs or suggest new features for the plugin.
