Sonarqube can't decorate Bitbucket Cloud pull request due to incorrect git hash

  • Must-share information:
    SonarQube: 9.4, Scanner: 6.32.8, Bitbucket Cloud, Jenkins: 2.332.3, Sonar-Scanner plugin: 2.14
  • What am I trying to accomplish:
    I am trying to enable Sonarqube to provide a Quality Gate status on Bitbucket Cloud pull requests
  • What I have tried:
    I’ve followed the documentation located here:
    Bitbucket Cloud Integration | SonarQube Docs
    Pull Request Analysis | SonarQube Docs
    and I see everything as expected on the Sonarqube side. However, I am not seeing anything in Bitbucket. Looking in the ce logs, I see this error:
    2022.05.26 16:42:26 INFO ce[AYEBP2_SJ21VTzo-vnkY][o.s.a.c.b.b.BitbucketCloudRestClient] Error returned by Bitbucket Cloud: 404 Resource not found
    2022.05.26 16:42:26 WARN ce[AYEBP2_SJ21VTzo-vnkY][c.s.F.D.A.B.E] Failed to create Bitbucket Cloud Quality Report for commit SHA ‘d543a5ec069d2b4cc430451c418b84d1b722506c’
    One thing about that commit has is that it doesn’t exist and the commit that should be used is 5544c0635e604bf46b8ad0c10708d22c6e21510a.
    Any thoughts on how I should proceed?


Welcome to the community!

At a guess, your pipeline is performing a local merge commit with an end result that SonarQube is trying to decorate a commit that doesn’t exist on the server.

You’ll need to prevent that merge commit from happening.


Thanks a bunch for the super fast reply.
Actually, I just figured out where that commit is coming from.
I have my jenkinsfiles in a separate repository from the code being analyzed. So, the jenkinsfile for Sonarqube gets checked out and then the actual code iis checked out to a subdirectory. That commit is from the jenkinsfile repository.
So, now my question is how can I specify which commit is used here?
I suppose I can just have the pipeline script be stored in the Jenkins UI, but that is antithetical to our workflow.

1 Like

I discovered the solution. I added this line to the sonar-scanner invocation:
-Dsonar.scm.revision=$(git rev-parse HEAD)
Make sure you are in the folder with the code you want to analyze so you get the correct hash from the command.

1 Like

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