Issues integrating Bitbucket PR Annotation


I’m attempting to integrate our Sonarqube analysis into Bitbucket so that any identified issues are annotated on the PR. I’m triggering Sonarqube analysis via a jenkins pipeline, using the SonarScanner jenkins plugin. I have the SonarScanner plugin configured to point to my instance, and I’m additionally passing values for the following variables to the execution as they appear to be required for PR analysis but not automatically set up by the SonarScanner plugin:

  • -Dsonar.pullrequest.key=${env.CHANGE_ID}
  • -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}
  • -Dsonar.pullrequest.base=${env.CHANGE_TARGET}

Analysis runs as expected and appears on my Sonarqube server. However! The annotation never makes it to my pull request :frowning:

For example, trying to perform analysis on a merge from branch DEV to branch MASTER gave me the following error on Sonarqube:

Failed to create Bitbucket Server Quality Report for commit SHA ‘a7589f8cdedb41ab52fe6d2f9b44d0762041553f’

Which indicates that sonarsource is attempting to annotate a PR for that commit over in Bitbucket. However, when Jenkins does a PR build, it merges the destination branch onto the current branch and runs the build on that result, to ensure that the builds would pass after the merge is complete. In my case, it merged the MASTER branch onto my DEV branch, producing commit ‘a7589f8cdedb41ab52fe6d2f9b44d0762041553f’. That commit doesn’t actually exist in Bitbucket though, it’s just created in the context of my build.

How do I get Sonarqube’s analysis to be associated with the correct commit, so that it can be annotated on a PR appropriately?

Looks like I misunderstood the configuration available in Jenkins. We were only configured for a single PR build with the behavior I detailed above. Instead, we had to enable the other flavor of PR build, the ‘head’ build which just runs on the code in the PR. Now it’s working!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.