Sonarcloud is analysing PRs via bitbucket pipeline, but not main branch?

We added the bitbucket pipeline as specified in the “wizard”:

image: maven:3-jdk-11

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

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarQube Cloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarQube Cloud
        caches:
          - maven
          - sonar
        script:
          - mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
        artifacts:
          - target/**

pipelines:                 # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
  branches:
    master:
      - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

Our “main” branch is set to develop in bitbucket - this is our default branch.

When we do PRs against develop, these are automatically analyzed by sonar via this pipeline. But this only analyses the chagnes, not the main repo.

In the main sonarcloud.io page for our project, it says:

"master" branch has not been analyzed yet.

how do we get sonar to analyze the main repo, not just the PRs , and to use develop, not master?

The docs say the main repo (develop branch in our case) is analyzed on first analysis, but this doesn’t seem to be the case.

Maybe the generated pipeline file should say “develop” instead of “master”?

Or maybe we need to delete the repo and start again?

Hi,

We’ve covered this multiple times. Here’s one excerpt, emphasis added:

It seems you want develop to act as the primary branch in the project currently under consideration. The rules are the same:

  • Analyze develop without passing a sonar.branch.name parameter. Since branch names are picked up automatically by the integrations, you may need to run this first analysis manually.
  • Via the SonarQube Cloud UI, rename the main branch to develop
  • Analyze as normal. Further analyses of the sonar.branch.name=develop branch will land in the project’s primary branch

I assume you’re asking here about which branch the PR is compared to? If so, it’s largely a question of making sure the prerequisites are in place.

 
HTH,
Ann