SonarCloud scan is not showing for Pull Requests on Bitbucket Cloud

  • ALM used Bitbucket Cloud
  • CI system used Bitbucket Cloud

Hi,
I am having issue while generating PR decorations for one of a private project. We are using Bitbucket CI pipeline to trigger the analysis (repository in bounded with SonarCloud project).

Pipeline is correctly triggering the SonarCloud analysis step under pull request and its completing successfully but PR decoration on Bitbucket platform is not showing, after checking SonarCloud platform i found analysis is happening under development branch (Main branch) but not for Pull Request.
Any suggestion why it is happening and how to resolve it.

PS: Other projects are working as expected.

Hi,

So you’re saying analysis is running as branch analysis rather than PR analysis?

Are you manually passing branch analysis parameters to analysis or is this being auto-detected by the scanner?

 
Ann

Yes, Instead of PR analysis it is running as branch analysis.

I am using Bitbucket CI pipeline to trigger PR analysis, and it is triggering analysis as well but on SonarCloud it is running as branch analysis rather than PR analysis.

Hi,

You don’t get decoration for branch analysis. You need to analyze it as a PR.

Do you know where the branch analysis parameters are coming from?

 
Ann

Can you please elaborate how do I get that information ?

What I am doing is simply triggering the analysis for Pull Request from Bitbucket CI under PR step.
I was following the same steps for other projects and was working fine for them.

Hi,

Can you post your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann

Hi @ganncamp,

Please find the analysis logs…
report.txt (23.9 KB)

Hi,

Thanks for the log. Nothing in it indicates that this is a PR analysis.

Take a look at the prerequisites for PR analysis.

 
HTH,
Ann

Hi @ganncamp,

If i am not mistaken you look at line number 43, 44, 45, 88, 94, 101 etc of Log file it clearly says PR. These are not found in branch analysis logs (I have verified that with branch analysis logs).

This is my bitbucket-pipelines.yml file structure to trigger analysis.

steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - sonar
        script:
          - pipe: sonarsource/sonarcloud-scan:2.0.0
            variables:
              SONAR_TOKEN: ${SONAR_TOKEN}

    - step: &check-quality-gate-sonarcloud
        name: Check the Quality Gate on SonarCloud
        caches:
          - sonar
        script:
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.6
            variables:
              SONAR_QUALITY_GATE_TIMEOUT: '600'

pipelines:
  pull-requests:
    '{feature/*,bugfix/*}':
      - step: *build-test-sonarcloud
      - parallel:
        - step: *other_steps
        - step: *other_steps
        - step: *check-quality-gate-sonarcloud

  branches:
    development:
      - step: *other_steps

Please guide me if i am doing anything wrong. I am following the same structure for other projects but its working fine there.

Hi,

Thanks for pointing those out. I overlooked them initially. There’s nothing in the analysis portion of the log that indicates those envvars were picked up & the analysis recognized as being for a PR.

Since it looks like you’re using the latest version of the sonarcloud-scan pipe, I’m going to flag this for more expert eyes.

 
Ann

Hi @sumit1

From investigation, I believe you created the project anew in SonarCloud. Can you tell if you still facing the same issue in this new setup?

If so, we would like to capture more information to investigate further:

  • turn on the debug mode, e.g.
variables:
    DEBUG: 'true'
  • print the values for those environment variables: CI, BITBUCKET_REPO_OWNER_UUID,
    BITBUCKET_REPO_UUID, BITBUCKET_BRANCH, BITBUCKET_COMMIT, BITBUCKET_PR_ID, and BITBUCKET_PR_DESTINATION_BRANCH

  • a reproducer repo/pipeline that we would be able to access would be even better

Thanks

Hi @AlxO, I am still facing the issue.

Both my SonarCloud project and Bitbucket repository are private. I don’t think its safe to share those information here in public platform.
Please message me privately or suggest any other way to share those information.

Thanks

Sure @sumit1 I’ll initiate a private discussion with you

This issue has been resolved!!

There was BITBUCKET_BRANCH repository variable defined in my repo which was masking the default branch of PR, hence causing this issue.

Simply removing BITBUCKET_BRANCH from repository variables resolved this issue.

1 Like

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