Sonar not working with multiple Azure DevOps projects

  • CI/CD system used: Azure DevOps
  • Languages of the repository: C#
  • Plan: Paid
  • Extension: 1.39.0 (Latest)

We successfully configured the SonarClound for our project (one repository) following the docs Azure DevOps | SonarCloud Docs and Setting Up SonarCloud for Azure Pipelines | by David Olivas. Everything was working well and the SonarClound Bot was adding comments on our pull requests based on the analysis of the modified code.

Recently we created another project (multiple repositories) in our Azure DevOps account and we followed the same guides to configure Sonar on this new project. Everything worked well, but now the SonarClound Bot stopped working in the first project. The analysis is still working and the reports are uploaded to sonarcloud.io but no comment is being added to the pull request anymore.

What we checked/found so far:

  • Compared the settings on sonarcloud.io for both projects. Almost the same except for the Project Key and some exclusions
  • There are no errors in the logs
  • The access token/service-connection is still working
  • The SonarScanner CLI has finished without errors (pipeline task)
  • SonarCloud Extension for Azure DevOps Version: 1.11.3 finished without error (pipeline task)

Questions:

  • Are there any restrictions to having 2 projects under the same organization?
  • What else can I do to find and solve the problem?
YAML pipelines
First project (that was working before)
name: 'SonarCloud Code Analysis'

trigger:
  - develop

pool:
  vmImage: ubuntu-20.04

steps:

  - checkout: self
    displayName: 'Checkout the code'

  - task: SonarCloudPrepare@1
    displayName: 'Prepare analysis on SonarCloud'
    inputs:
      SonarCloud: 'SonarCloud'
      organization: '*****' # omitted 
      scannerMode: 'MSBuild'
      projectKey: '*****' # omitted 
      projectName: '*****' # omitted 

  - task: DotNetCoreCLI@2
    displayName: 'dotnet build solution'
    inputs:
      projects: '*.sln'

  - task: SonarCloudAnalyze@1
    displayName: 'Run Code Analysis'

  - task: SonarCloudPublish@1
    displayName: 'Publish Quality Gate Result'
    inputs:
      pollingTimeoutSec: '300'
Second project (that is working)
# https://aka.ms/yaml

name: 'SonarCloud Code Analysis'

parameters:
  - name: projectFilter
    type: string
    default: "**/*.csproj"

resources:
  repositories:
  - repository:  '*****' # omitted 
    type: git
    name:  '*****' # omitted 
    ref: master

trigger:
  - develop

pool:
  vmImage: ubuntu-20.04

steps:

  - checkout: self
    displayName: 'Checkout the code'

  - checkout:  '*****' # omitted 
    displayName: 'Checkout code'

  - task: SonarCloudPrepare@1
    displayName: 'Prepare analysis on SonarCloud'
    inputs:
      SonarCloud:  '*****' # omitted / different from the other project
      organization:  '*****' # omitted 
      scannerMode: 'MSBuild'
      projectKey:  '*****' # omitted 
      projectName:  '*****' # omitted / different from the other project
      extraProperties:
        sonar.projectBaseDir=$(System.DefaultWorkingDirectory)/MyRepo

  - task: DotNetCoreCLI@2
    displayName: dotnet build
    condition: succeeded()
    inputs:
        projects: ${{ parameters.projectFilter }}

  - task: SonarCloudAnalyze@1
    displayName: 'Run Code Analysis'
    condition: succeeded()

  - task: SonarCloudPublish@1
    displayName: 'Publish Quality Gate Result'
    condition: succeeded()
    inputs:
      pollingTimeoutSec: '300'
1 Like

I’ll reach out privately for some additional information.

We rerun the procedures described by the links I shared in the description and that solved the issue. We probably missed something int he first tries.

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