SonarCloud setup Bitbucket Monorepo


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

 |    |
 |    - project1
 |           | -src
 |    - project2
 |    - project3
 |- libs
      - libs1
      - libs2
      - ....

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


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

    bundler: vendor/bundle
    sonar: ~/.sonar/cache
      memory: 4096
    - step: &build-test-sonarcloud
        name: Analyze Build
        size: 2x
          - node
          - sonar
          - npm install --quiet
          - pipe: sonarsource/sonarcloud-scan:1.4.0
              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.