Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Configuration Checklist

  1. Verify your SonarQube SonarQube™ server settings in global settings of Bitbucket

  2. Run SonarQube SonarQube™ source code analysis for main branch

    1. Configure the source code analysis

    2. Analysis results must be visible in SonarQubeSonarQube™

  3. Configure corresponding SonarQube SonarQube™ project in repo settings of Bitbucket

  4. Go to source code view and see the existing Sonar issues/stats

    1. You should see the SonarQube SonarQube™ statistics and issue annotation

    2. Statistics and annotations are missing? Verify your repository configuration:

      1. Did you configure the correct analysis directory?

      2. Does the SonarQube SonarQube™ project key match with the configuration in Bitbucket?

  5. Create a pull request with issues in the code.

  6. Run SonarQube SonarQube™ source code analysis for source branch of your pull request.

  7. Go to the pull request view and check if the Sonar analysis results are visible. You should see a quality gate status overview, and issue annotations in the pull request diff.

    1. An error

      hints at a wrong Sonar analysis configuration or a wrong analysis directory setting

    2. No issue annotations:

      1. Verify that you can see the issues that should be shown in SonarQubeSonarQube™

      2. Do the issue annotations appear after clicking “Refreshing Sonar Sonar™ analysis” in the pull request overview? Then check your Webhook configuration

1.

...

Sonar™ issue information not found

Problem: In the pull request, you get the following error:

...

Resolution: Verify that you have configured a webhook for the Sonar Include Code Quality for Bitbucket app under SonarQube SonarQube™ → Administration → Configuration → Webhooks and that the last delivery status is OK (green). If it is red like in the following screenshot, check our Webhook troubleshooting guide:

...

2. Failed to get

...

statistics: Component key not found

Problem: In the pull request, you get the following error:

...

Resolution: The app requires that you analyze the branch of your pull requests with SonarQubeSonarQube™. Check that you have a SonarQube SonarQube™ project with that key:

...

If you are sure that there is a project in SonarQube SonarQube™ with such a key in SonarQubeSonarQube™, check the selected SonarQube SonarQube™ Edition in the Sonar server configuration:

...

3. No annotations for

...

SonarQube™ issues within a pull request

Problem: No annotations for SonarQube SonarQube™ issues are shown in a pull request, although you expect some:

...

a) The app only shows annotations with minimum issue severity (e.g. MAJOR) according to the repository settings option “Min. severity to show”. So if you cannot see annotations because all Sonar issues in your pull request are of severity MINOR, check this setting and update it accordingly.

b) Verify that you have configured a webhook in SonarQube SonarQube™ for the Sonar Include Code Quality for Bitbucket app and that the last delivery status is OK (green). If it is red like in the following screen shot or if you don’t see a webhook entry for this app, check our Webhook troubleshooting guide:

...

Resolution: is caused by having an incompatible app version for their SonarQube SonarQube™ version. They need to upgrade the app to the latest version, that should resolve the issue.

...

Check if you have a webhook configuration in SonarQube SonarQube™ Admin -> Configuration -> Webhooks with the name ch.mibex.bitbucket.sonar:

...

If there is no webhook configuration for Bitbucket, please check the Bitbucket Server log for any errors. Also, check that your network/firewall configurations allow communication between SonarQube SonarQube™ and Bitbucket.

If you have a webhook configuration, you should see Sonar annotations in your pull requests, after a new analysis has been run.

If no annotations are shown, please check the webhook delivery status in SonarQube SonarQube™ under SonarQube SonarQube™ Admin -> Configuration -> Webhooks. If you see a 502 Server Unreachable error, then it could be either that

  • you are using localhost or a wildcard address for Bitbucket which is not supported because SonarQube SonarQube™ does not allow these. Please use the real Bitbucket hostname instead.

  • you do not have a valid HTTPS certificate for Bitbucket configured in SonarQubeSonarQube™'s JVM, see this community article for more information.

  • you have invalid proxy settings that prevent SonarQube SonarQube™ from connecting Bitbucket: check your -Dhttp.proxyHost and -Dhttp.nonProxyHosts JVM arguments

Info

For SonarQube SonarQube™ 7.7, please make sure to pass -Dsonar.analysis.scmRevision=COMMIT_ID to your SonarQube SonarQube™ analysis. For newer SonarQube SonarQube™ versions, this is not necessary anymore.

6. Links back to

...

SonarQube™ not working/wrong URL

Two places to check the URL:

  1. On Bitbucket in Sonar Include Code Quality for Bitbucket server config:

    1. Ensure to properly set the Sonar Display URL in your Sonar Include Code Quality for Bitbucket Server Configuration, if it’s different then Application URL.

  2. On SonarQubeSonarQube™: make sure to set the Server base URL correctly on your SonarQube SonarQube™ server:

    1. Log in to the SonarQube SonarQube™ dashboard and click on the “Administration” tab.

    2. Browse to the “Configuration -> General settings -> General” menu.

    3. Under the “General” section, change the “Server base URL” to the correct server domain name.

    4. Save the changes.

...