PR Decoration with Bitbucket Cloud

Hey,

I am trying to setup PR decorations with Bitbucket cloud, but the documentation doesn’t fully explain how this can be done. How can I pass the “sonar.pullrequest.bitbucketcloud.repository” + “sonar.pullrequest.bitbucketcloud.owner” values to the Bitbucket pipeline job?

https://sonarcloud.io/documentation/analysis/pull-request/


Bitbucket Cloud PR Decoration

To add PR decoration on Bitbucket Cloud, you need to update some settings.

Updating Your Bitbucket Cloud Settings

Setting Name Description Example value
sonar.pullrequest.bitbucketcloud.repository UUID of the Bitbucket Cloud Repo {d2615dd4-550d-43e5-80c4-665f951e5d6e}
sonar.pullrequest.bitbucketcloud.owner UUID of the Bitbucket Cloud Owner {4f9fd128-1b08-49ec-bf2c-f094163cff4d}

My guess Bitbucket pipeline yml file that runs correctly but doesn’t decorate the PR:

image: maven:3.3.9

clone:
  depth: full              # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - maven
          - sonar
        script:
          - mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -D sonar.pullrequest.bitbucketcloud.owner={XYZ} -D sonar.pullrequest.bitbucketcloud.repository={ABC}

        artifacts:
          - target/**

pipelines:   
  branches:
    master:
      - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

Hi,

If you’re running the scanner inside Bitbucket Pipeline, you shouldn’t have to configure those properties.
The scanner will read them automatically from environment variable available when running inside Bitbucket Pipelines.

Could you try without the parameters to see if it correctly analyze your PR?

Hey Benoit,

The analysis is running correctly, but the PR is not getting decorated with comments in Bitbucket.

Is there any further config to get setting required to activated them?

Hi @Sean_Harrison,

Unfortunately, PR decoration do not create comments in the diff of the PR for now. This is something we would like to improve in the future, but probably not before the end of the year.

Feel free to watch and vote for this MMF.

Cheers,

2 Likes

@aurelie it seems we have to have an account to watch and vote on https://jira.sonarsource.com/. Any way we can cast our vote?

You can signup here

1 Like

Any update on this?

I signed up for an account to track the MMA, but it says I don’t have access.