Monorepo analysis

  • Azure DevOps
  • Application is a monolith/monorepo where we have both, backend .net and, frontend vue app.
  • On our Sonarcloud organisation we have both projects and they are set up as monorepo, however we are only getting frontend analysis out of this setup - without the frontend analysis - backend analysis works without any issues
  • C#, typescript, html, css

In our pull request pipeline yml we have following commands

   ...
   ...
  - task: Npm@1
    displayName: 'npm install'
    inputs:
      command: 'install'
      workingDir: 'Circit.Frontend'
      verbose: true

  - task: Npm@1
    displayName: 'npm build'
    inputs:
      command: custom
      workingDir: Circit.Frontend
      verbose: true
      customCommand: run build
   ...
   ...
  - task: SonarCloudAnalyze@1
  
  - task: SonarCloudPublish@1
    inputs:
      pollingTimeoutSec: '300'

Hi,

Welcome to the community!

So… when you set up frontend analysis, backend doesn’t work, and when you remove frontend analysis, backend starts working?

Per the docs:

Note that for the SonarCloud monorepo setup to work properly, you have to build each project separately and use a unique project key for each one.

So I would expect to see two different pipelines for this. Is that the case & you just didn’t bother to post the other one?

 
Ann

Hi Ann,

Thanks for a warm welcome!

That’s correct, each one of them independently works, but if both analysis are put into a single pipeline we only get the later - in this case frontend one.

In fact we have this in one pipeline, apologies I copied over the wrong thing.
Would this be possible do in a single pipeline as we would like to have our PR pipeline as mandatory quality gate which would do both analysis

Here is an updated snippet.

  - task: SonarCloudPrepare@1
    inputs:
      SonarCloud: 'SonarCloud'
      organization: 'circit'
      scannerMode: 'MSBuild'
      projectKey: '**api_key**'
      projectName: '**api_project_name**'
      
  - task: SonarCloudPrepare@1
    inputs:
      SonarCloud: 'SonarCloud'
      organization: 'circit'
      scannerMode: 'CLI'
      configMode: 'manual'
      cliProjectKey: '**frontend_key**'
      cliProjectName: '**frontend_project_name**'
      cliSources: './Circit.Frontend'

...
// frontend build
  - task: Npm@1
    displayName: 'npm build'
    inputs:
      command: custom
      workingDir: Circit.Frontend
      verbose: true
      customCommand: run build
   ...

// api build
  - task: DotNetCoreCLI@2
    displayName: 'dotnet build $(buildConfiguration)'
    inputs:
      command: 'build'
      projects: 'Circit.sln'
      arguments: '--configuration $(buildConfiguration)'
   ...
  - task: SonarCloudAnalyze@1
  
  - task: SonarCloudPublish@1
    inputs:
      pollingTimeoutSec: '300'

Thanks,
Roberto

Hi Roberto,

Thanks for coming back with the details. I’ll admit I’m a bit out of my depth here, so I’m going to flag this for more expert eyes.

 
Ann

Hi @Roberto_Bubalo

The azure devops extensions still work as a sequence of tasks : Prepare, Analyze, and Publish (this one is optional)

Here also, you are building with 2 different build technologies, and I’m afraid, if you build your .NET code with the “manual” config mode, it won’t work.

So then what you’ll have to do is to :

  • Build your frontend code with the config mode “manual”, making sure your are following the sequence mentioned above (Prepare, build steps if relevant, analyze) → Everything will be pushed on your frontend project on SonarCloud
  • Then do the same for the backend code : Prepare (“msbuild” config mode), ** .NET build steps ** and analyze.

Hope that makes sense.

Mickaël

1 Like

Hi mickaelcaro

Apologies for late response, that works great.
Thanks a million!

Roberto

2 Likes

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