Display the 'custom' branch in Sonarcloud GUI from where the PR is created in bitbucket


We want to do the code coverage with Sonarcloud using Jenkins for every pull request created in bitbucket cloud.

For this, we have used ‘Bitbucket pull request builder’ parameter as per the following image:

The code analysis was automatically done in Jenkins whenever a pull request is created in Bitbucket.

But, why the branch in the Sonarcloud is still showing as ‘Master’ even though if we creating a pull request in ‘Test’ branch?

Is is possible to show the the exact branch (in sonarcloud GUI) from where the pull request is created ?

And welcome to the community forum!

Our documentation about pull request analysis parameters should help you. When doing the analysis of a pull request you should specify the sonar.pullrequest.base parameter to tell SonarCloud what is the target branch of this PR.

Hi @Gregoire_Aubert ,

Thanks for the instant reply.

As long as we update the branch in Sonar.pullrequest.branch, its fine. But the pull request will be created for every branch during short intervals and mentioning the branch and changing the branch name in in Sonar.pullrequest.branch always is tough.
Is there any possibility to mention in the parameter to pick the branch automatically from where the PR is created ?

I guess that in the payload of the Bitbucket webhook that triggers the Jenkins job you should have the PR id and the target of the PR so that you can set it dynamically from there when triggering the job.

Hi @Gregoire_Aubert,

Can you please mention it with any screenshot or documentation if possible?

Thank you,

I don’t know which webhook you use exactly, but for example, looking at the pull request event payload from Bitbucket we can see that there is a destination.branch field which is probably what you should use as a value for the sonar.pullrequest.base parameter when you start the scanner job.

You can also find a lot of documentation about how to use the scanner for Jenkins here. And how to setup your PR analysis here.

Hi @Gregoire_Aubert,

Yes, after mentioning the required sonar.pullrequest.base, sonar.pullrequest.branch, sonar.pullrequest.key parameters, we can able to display the name and coverage of the PR’s in sonarcloud UI :


But every time whenever a PR is created in bitbucket, we need to manually change the above pull requests parameters in Jenkins under execute scanner properties. Can this be automated without any manual change every time? So that the Jenkins itself should pick the pull requests parameters automatically and post it as in the mentioned screenshot?

Thank you,


I have sorted it out by using the ‘default environmental variables’ in Jenkins like GIT_BRANCH.

Thank you,

1 Like