In order for Include Code Quality for Bitbucket to include SonarQube™ analysis results in your Bitbucket instance, your build pipeline must trigger a SonarQube™ analysis.
As such it must execute the Sonar™Scanneror one of its build system-dependent alternatives(e.g. the SonarQube™ Maven plug-in).
Whichever external system you use to execute the SonarQube™ scan, you need to run it with the correct parameters for your SonarQube™ application. Use the analysis parameter matrix provided below.
Analysis Parameter Matrix
The table shows the minimally necessary parameters to get Include Code Quality for Bitbucket to work with Sonar™Scanner. Look at the SonarQube™ documentation for additional parameters or different scanning methods.
-Dsonar.pullrequest.key=<pull request id from Bitbucket>
-Dsonar.pullrequest.branch=<source branch name of pull request>
-Dsonar.pullrequest.base=<destination branch name of pull request>
SonarQube™ versions 7.9.x and 8+ only allow certain characters in their project keys:[0-9a-zA-Z:-_.].
Branch names typically contain / and cannot be used.
Use the same replacement character as configured in the SonarQube™ server configuration in the app’s settings in Bitbucket (Bitbucket Admin → Include Code Quality) under ‘Branch renaming for Project Keys’.
To replace illegal characters with the replacement character, the following sed expression can be used in your CI/CD configuration:
sed s/[^0-9a-zA-Z:_.\-]/'<YOUR_CONFIGURED_CHAR>'/g
Branch Analysis
Parameter not supported.
The SonarQube™ Community Edition does not handle branches and pull requests in a single project. As such, a separate SonarQube™ project for each branch is used to show SonarQube™ information for pull requests and branches.
The branch must be included in SonarQube™ projectKey asBRANCH_NAME (see Common Parameters above)
Pull Request Analysis
Parameter not supported.
Use the source branch name of pull requests as BRANCH_NAME in SonarQube™ projectKey.
-Dsonar.pullrequest.key=<pull request id from Bitbucket>
-Dsonar.pullrequest.branch=<source branch name of pull request>
-Dsonar.pullrequest.base=<destination branch name of pull request>