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:
Analysis runs as expected and appears on my Sonarqube server. However! The annotation never makes it to my pull request
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?