SonarCloud setup Bitbucket Monorepo

Hello,

I am trying to setup SonarCloud inside one mono repo in my company.
The mono repo is setup using NX and contains 3 projects, and multiple lib (each project can use those lib). My Monorepo is hosted on bitbucket and I am running the pipeline using bitbucket pipeline.

I would like to analyze a single project for now, and eventually expand to the other 2.

Project structure

root
 |-apps
 |    |
 |    - project1
 |           | -src
 |        sonar-project.properties
 |    - project2
 |    - project3
 |- libs
      - libs1
      - libs2
      - ....

I create a Project in SonarCloud, and toggled the Enable support for monorepo. Then setup a sonar-project.properties at the root of project 1

sonar.projectKey=xxxx
sonar.organization=xxxx
sonar.projectBaseDir=apps/project1
sonar.sources=/src

On the pipeline, I copied some stuff to make it work on bitbucket

definitions:
  caches:
    bundler: vendor/bundle
    sonar: ~/.sonar/cache
  services:
    docker:
      memory: 4096
  steps:
    - step: &build-test-sonarcloud
        name: Analyze Build
        size: 2x
        caches:
          - node
          - sonar
        script:
          - npm install --quiet
          - pipe: sonarsource/sonarcloud-scan:1.4.0
            variables:
              SONAR_TOKEN: ${SONAR_TOKEN}
              SONAR_SCANNER_OPTS: -Xmx2048m
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.6

Finally, I setup this like this to ignore some folders on all projects.

Now running this result in
INFO: 1456 source files to be analyzed

But the result of the analysis contain only one file and it s bitbucket-pipeline and it say “32 new lines added”

I guess something is wrong in the config, so I would like to have sone insight in what could I be doing wrong.

Thanks !

Hey there.

Two points:

  • Enable support for monorepo… unfortunately doesn’t do what it sounds like it does. You will need to setup a monorepo through the project creation wizard to create multiple projects, which you narrow the focus (analysis scope) for each repo in your monorepo.

This sounds expected if your first analysis is a pull request analysis (where only changed files are analyzed). You should see full results once the analysis runs on your main branch.