Pull Request Decoration with Bitbucket Server and Bamboo

Hi,

I’m working on getting SonarQube analysis and and decoration set up for each new pull request.
We use Bitbucket server and bamboo for CI. Our project is written in C#
So for every pull request going into our master branch we currently run a bamboo build plan. This build must pass before a pull request can be merged. So along with this we’d like the SonarQube analysis to pass before merging in.
I’ve read the documentation for this. However the documentation that describes Analysis Parameters is confusing. Where and how do I set these parameters?

This is what the documentation states:

Analysis Parameters

These parameters enable PR analysis:

|Parameter Name|Description|
sonar.pullrequest.key Unique identifier of your PR. Must correspond to the key of the PR in GitHub or TFS. example: sonar.pullrequest.key=5
sonar.pullrequest.branch The name of the branch that contains the changes to be merged.
example: sonar.pullrequest.branch = feature/my-new-feature
sonar.pullrequest.base The long-lived branch into which the PR will be merged.
Default: master, example: sonar.pullrequest.base=master

Brett

Hi @bparseki,

Welcome to the community forum!
To be able to help you, we would need a bit more information such as the version of SonarQube and the edition you are running (Community, Developer, Enterprise, Data Center).
And the version of Bitbucket Server as well.

To add, you will find a lot of information on this link: https://docs.sonarqube.org/latest/analysis/pull-request/
–> Especially related to PR decoration (in Bitbucket Server).

Carine

1 Like

I’m using the Enterprise Edition version 7.7. The version of Bitbucket is 6.4.0. And yes I’ve read that page in your documentation. My confusion is where and how I need to set those Analysis Parameters.

hi @bparseki - you must pass them to SonarQube Scanner for MSBuild begin step.

Below is the begin step for a github repository (but except the sonar.pullrequest.github.repository , everything should work for your BitBucket integration)

SonarScanner.MSBuild.exe begin^
/k:sonaranalyzer-dotnet ^
/n:"SonarAnalyzer .Net" ^
/d:sonar.host.url=${sonarCloudUrl} ^
/d:sonar.login=$sonarCloudToken ^
/o:sonarsource ^
/d:sonar.cs.vstest.reportsPaths="**\*.trx" ^
/d:sonar.cs.vscoveragexml.reportsPaths="**\*.coveragexml" ^
/d:sonar.analysis.prNumber=$githubPullRequest ^
/d:sonar.analysis.sha1=$githubSha1 ^
/d:sonar.pullrequest.key=$githubPullRequest ^
/d:sonar.pullrequest.branch=$githubPRBaseBranch ^
/d:sonar.pullrequest.base=$githubPRTargetBranch ^
/d:sonar.pullrequest.provider=github ^
/d:sonar.pullrequest.github.repository=$githubRepo ^
/v:$leakPeriodVersion

You can also take a look at the CI scripts of the sonar-dotnet project.

  • at line 146 you can see the begin invocation
  • at line 227 you can see the additional parameters needed for a pull request

See https://docs.sonarqube.org/7.7/analysis/pull-request/ for your specific analysis parameters

I hope this helps.