Looking for Pullrequests Documentation For Bitbucket Cloud

I’m looking for documentation on how to setup Sonarcloud for Bitbucket Cloud on the level of pull requests.

I could find this:

https://sonarcloud.io/documentation/integrations/bitbucketcloud

but it has not enough detail for me regarding having wrong link in the widget on the pull request page in Bitbucket (the link is displayed in the widget sonarcloud signals it red/failed).

I’m pretty sure I’m missing some configuration directives here, the blog post from April wrote about some updates for Bitbucket Cloud so I guess I’m perhaps just looking for these.

Can you explain what you experience? Where does the link bring you?

The pull request widget:

image

has a link (“See all issues on Sonarcloud”) and that link goes to the Sonarcloud website which then gives an error message:

The requested project does not exist.
Either it has never been analyzed successfully or it has been deleted.

And that is just not true, the project does exists and it has not been deleted.

If you go on your SonarCloud project, do you see the PR in the top dropdown list? Like in this example:

image

No, it is not here. We only have Short-lived branches there.

OK, so assuming that you are using Bitbucket Pipelines, I guess I know what’s happening:

  1. You created a branch on which you pushed some code
  2. Pipelines triggered a build: this branch got analyzed and you have results in SonarCloud - great :slight_smile:
  3. Then you created a PR on that branch in Bitbucket Cloud, and :boom: : the link is not valid

If this is the path you followed, the reason why the link is not valid is that Bitbucket Pipelines does not trigger a build when you create a PR:

  • This explains why you don’t see the PR in SonarCloud Web UI
  • Which in turn explains why the “See all issues on SonarCloud” link is not valid

If you push a new change on your branch, then Pipelines will trigger a build, the PR will appear in SonarCloud and the link will then be valid. (Hopefully! :crossed_fingers:)

I’m going forward in baby steps. Found out, that in Administration (Settings) for Pull Requests the provider was not set. I did set it to Bitbucket.

But so far for that project I don’t see any pull requests in the branch view. If the Short-Lived Branches are created for every pull request, could that be in conflict with the Pull Request Feature?

I guess I also need to do some settings w/ the properties file while Sonar Scanning, right?

/e: I’m getting closer, first pull request in the drop-down list :wink:

I’ve problems to obtain the value for sonar.pullrequest.key inside am Bitbucket Cloud pipeline. Do you have any idea about that?

/e: I could solve that now :grinning:. As we have PHP quite centrally I created a curl + php script. Searching the open pullrequests for the branch in the bitbucket cloud pipeline via the Bitbucket Cloud REST API.

I also set the target branch, but it seems that this one is ignored.It should be develop but somehow Sonarcloud hangs on the master branch as the default branch. Any ideas on how to control that in detail?

Hi Nico,

I don’t understand why you need to do all this. If you’re using Bitbucket Pipeline, SonarCloud knows how to get those information directly out of the Pipeline environment variable, you should not have to worry about this. Did you look at the sample project listed in the FAQ of https://sonarcloud.io/documentation/integrations/bitbucketcloud?

Thanks for all your detailed feedback.

It is so maybe because I’ve overlooked the mvn (maven?) command. Which container image that is, the default Bitbucker Cloud Pipline one that is 2TB+?

What do I do if I don’t want to run mvn?

I have found not Bitbucket Cloud Pipeline Environment Variable which transports the Bitbucket Pull Request ID

Could it be an issue that we’re running Bitbucket Cloud Pipelines in alpha?

/e: I’d like to follow as closely as possible to the reference you’ve linked, I guess I’m just missing which image that is. I guess that image will also do the scanning so a good out of the box solution. Please enlighten me :slight_smile:

@Fabrice_Bellingard: This is not with maven, but is this the suggested image / way to do it: https://bitbucket.org/bellingard/fab/src/master/bitbucket-pipelines.yml ?

  • image: node:6.9.4
  • script:
    • npm install -g sonarqube-scanner
    • sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=bellingard-bitbucket -Dsonar.login=$SONARCLOUD_TOKEN

(organization to change for sure)