Azure devops pipeline: The SonarScanner for MSBuild integration failed

I’m not able to get the pipeline to run successfully with az devops.
This is the yml

trigger:
  branches:
    include:
    - dev

  paths:
    include:
    - Kube/*
    - Services/*
    - Core/*
    - azure-pipelines.api.yml
    - docker-compose.yml
    - docker-compose.override.yml
    exclude:
    - Web/*
    - Kube/web/*
    - docker-compose-adminweb.yml
    - docker-compose-adminweb.override.yml

resources:
- repo: self

name: $(Year:yy)$(DayOfYear)$(Rev:.r)

variables:

  # Build platform
- name: buildPlatform
  value: 'Any CPU'
- name: buildConfiguration
  value: 'Release'

  # Environment variables used by docker-compose
- name: mainVersion
  value: 1
- name: minorVersion
  value: 0 
- name: VERSION
  value: '$(mainVersion).$(minorVersion).$(build.buildNumber)'
- name: DOCKER_REGISTRY
  value: '$(dockerRegistryId).azurecr.io'

  # Build Agent VM image name
- name: vmImageName
  value: 'ubuntu-latest'
- group: 'nuget.config'
  
stages:
- stage: Build
  displayName: Build stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
      - checkout: self
        fetchDepth: 0
      

      - task: SonarCloudPrepare@1
        inputs:
              SonarCloud: 'Sonarcloud'
              organization: ''
              scannerMode: 'MSBuild'
              projectKey: ''
              projectName: ''
        displayName: "Prepare SonarCloud"
            
    # Install dotnet core 8.0.x SDK
      - task: UseDotNet@2
        displayName: 'Install .NET Core .0.x SDK'
        inputs:
          version: 8.0.x
          performMultiLevelLookup: true
      
        # Install dotnet ef and create migration scripts
      
      - script: dotnet tool install --global dotnet-ef --version 8.0.3-*
        displayName: 'Install .NET EF 8.0.3-*'
     

      # Verify Docker build agent installation status
      - script: sudo service docker status
        displayName: 'Verify docker installation status'
      - task: qetza.replacetokens.replacetokens-task.replacetokens@3
        displayName: 'Replace tokens in nuget.docker.config'
        inputs:
          targetFiles: |
            nuget.docker.config
          escapeType: none
      
    # Build container images
      - task: DockerCompose@0
        displayName: Build container images
        inputs:
          action: Build services
          azureSubscriptionEndpoint: '$(subscriptionEndpoint)'
          dockerComposeFile: docker-compose.yml       
    
      - task: DockerCompose@0
        condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/'))) # Ignore PR
        displayName: Publish container images
        inputs:
          action: Push services
          azureSubscriptionEndpoint: '$(subscriptionEndpoint)'
          azureContainerRegistry: $(DOCKER_REGISTRY)
          dockerComposeFile: docker-compose.yml

      - publish: Kube
        artifact: Kube
        displayName: Publish Kubernetes manifests  

      - task: SonarCloudAnalyze@1
        inputs:
              jdkversion: 'JAVA_HOME_17_X64'
        displayName: "Code Analysis"
      - task: SonarCloudPublish@1
        inputs:
              pollingTimeoutSec: '300'
        displayName: "Publish Result"

Hi,

What’s the error you’re experiencing? Can you provide your logs?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Ann