Pull request decoration with Jenkins+Bitbucket uses constant sonar.pullrequest.key

We are using Bitbcuket pull request builder plugin in Jenkins to perform the sonarcloud analysis for the created PR.

We have given every parameter and as a result the sonarcloud scan for every PR created is successfully displayed in Sonarcloud. But,

The value of sonar.pullrequest.key is set constant which is set as 5. So, whenever we create a pull request no.10 in Bitbucket, the PR analysis of the sonarcloud is appended with 5 in the dashboard (Ideally it should be 10) . Also, whenever we raise a new PR no.11, the analysis of the old PR in the sonarcloud (Appended with 5 in the dashboard) is updating with the new value and as a result we could not able to view the old PR and the sequences of created pull request in sonarcloud.

I know that changing the sonar.pullrequest.key value everytime according to the created PR in bitbucket will fetch us results, but who can we make it process as a automated one?


I’m not familiar with the “Bitbucket pull request builder plugin in Jenkins”. Can you please share a link to the plugins homepage?

As for sonar.pullrequest.key being constant, please verify the analysis command that is being used. How is this property specified?

  • Is it part of the analysis command?
  • Is it by any chance from a file in your repository? (Could be sonar.properties file, or in case of a Maven project, could be in pom.xml. Please check this property is not in any file under version control!)
  • Is it expected to be passed by the “Bitbucket pull request builder plugin in Jenkins”?

Hi @janos,

Plugin details : https://www.google.com/url?sa=t&source=web&rct=j&url=https://plugins.jenkins.io/bitbucket-pullrequest-builder/&ved=2ahUKEwj3lYTQjsnpAhVN4nMBHZytDRkQFjAAegQIAhAC&usg=AOvVaw0KZCSQgF0rxYrHOEzbxuYO&cshid=1590206986968

We are using this Plugin in Jenkins and using sonar.pullrequest.key in execute sonarqube parameters in Jenkins.


Any solution to this ?

Do you set the value of sonar.pullrequest.key manually in the Jenkins parameters?

Hi @janos,

Yes, i have set it manually and that is causing problem whenever a new PR is created the analysis of the old PR in sonarcloud dashboard is been replaced with the new one’s

I see. Setting this value is a Jenkins parameter is not a good solution for you.

We do not provide support for the Jenkins plugin you mentioned. But in principle this looks completely doable. You just need to find a way to determine the pull request number at the time the job runs, and then pass it to the scanner command as a -Dsonar.pullrequest.key=... parameter. The pull request number may be readily available as an environment variable, or you may have to extract it from the pull request URL that was used to clone the repo. I found this example that could be useful for you.