AzureDevops- .Net project analysis with sonarQube error

I have setup my Sonar server on my AKS (Azure kubernets cluster) and using Sonar docker image version (image: sonarqube:7.1).

I have my CI/CD pipeline in Azure Devops for .net application and I am using AzureDevops SonarScanner ( sonar) .

When I am running my pipeline I am getting this error:

Description : Run scanner and upload the results to the SonarQube server.
Version : 4.11.0
Author : sonarsource
Help : Version: 4.11.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.
/usr/bin/dotnet /home/vsts/work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.11.0/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll end
SonarScanner for MSBuild 4.10
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
##[error]The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:

  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
    The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.

My Pipeline looks like this:

- task: SonarQubePrepare@4
  inputs:
    SonarQube: 'SonarQube-Dev'
    scannerMode: 'MSBuild'
    projectKey: 'Test'
    projectName: 'Test'
    extraProperties: |
      # Additional properties that will be passed to the scanner, 
      # Put one key=value per line, example:
      # sonar.exclusions=**/*.bin
      sonar.projectBaseDir=/src
      sonar.sources=src  
- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    #feedsToUse: 'select'
    workingDirectory: '/src'
  
- task: MSBuild@1
  inputs:
    solution: '/*.sln'
    restoreNugetPackages: true
    clean: true   
    
- task: SonarQubeAnalyze@4

Hi @sangam and welcome to the community !

First, you don’t have to set sonar.sources and sonar.projectBaseDir, the Scanner will set them for you.
Second, if you run the dotnet build command in verbose mode, do you see any Sonar-related messages being displayed ?

Thanks.

1 Like

Hi Mickael,

Thank You for your response. As suggested I removed sonar.sources and sonar.projectBaseDir. I added this just to try if it helps anyway.

Here is full build log-

##[debug] /version

##[debug] /nologo

/usr/bin/msbuild /version /nologo

16.6.0.32601

##[debug]Exit code 0 received from tool '/usr/bin/msbuild'

##[debug]STDIO streams have closed for tool '/usr/bin/msbuild'

##[debug]system.defaultWorkingDirectory=/home/vsts/work/1/s

##[debug]defaultRoot: '/home/vsts/work/1/s'

##[debug]findOptions.allowBrokenSymbolicLinks: 'false'

##[debug]findOptions.followSpecifiedSymbolicLink: 'false'

##[debug]findOptions.followSymbolicLinks: 'false'

##[debug]matchOptions.debug: 'undefined'

##[debug]matchOptions.nobrace: 'undefined'

##[debug]matchOptions.noglobstar: 'undefined'

##[debug]matchOptions.dot: 'undefined'

##[debug]matchOptions.noext: 'undefined'

##[debug]matchOptions.nocase: 'undefined'

##[debug]matchOptions.nonull: 'undefined'

##[debug]matchOptions.matchBase: 'true'

##[debug]matchOptions.nocomment: 'undefined'

##[debug]matchOptions.nonegate: 'undefined'

##[debug]matchOptions.flipNegate: 'undefined'

##[debug]pattern: '/*.sln'

##[debug]expanding braces

##[debug]findPath: ''

##[debug]skipping empty path

##[debug]0 final results

Finishing: MSBuild

And here Sonar log-

Output directory: /home/vsts/work/1/.sonarqube/out
Config file: /home/vsts/work/1/.sonarqube/conf/SonarQubeAnalysisConfig.xml
Generating SonarQube project properties file to /home/vsts/work/1/.sonarqube/out/sonar-project.properties
##[error]The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
##[debug]Processed: ##vso[task.logissue type=error;]The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.%0D%0APossible causes:%0D%0A  1. The project has not been built - the project must be built in between the begin and end steps%0D%0A  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.%0D%0A  3. The begin, build and end steps have not all been launched from the same folder%0D%0A  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
Writing processing summary to /home/vsts/work/1/.sonarqube/out/ProjectInfo.log
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
##[error]10:32:32.387  Post-processing failed. Exit code: 1
##[debug]Processed: ##vso[task.logissue type=error;]10:32:32.387  Post-processing failed. Exit code: 1
10:32:32.387  Post-processing failed. Exit code: 1
##[debug]Exit code 1 received from tool '/usr/bin/dotnet'
##[debug]STDIO streams have closed for tool '/usr/bin/dotnet'
##[debug]task result: Failed
##[error]The process '/usr/bin/dotnet' failed with exit code 1
##[debug]Processed: ##vso[task.issue type=error;]The process '/usr/bin/dotnet' failed with exit code 1
##[debug]Processed: ##vso[task.complete result=Failed;]The process '/usr/bin/dotnet' failed with exit code 1
Finishing: SonarQubeAnalyze

Hi ,

I tried many things in between and look like when I used .NetCLIBuild insted of MSBuild step then my sonar analysis started working .

Now my pipeline looks like this.

   - task: DotNetCoreCLI@2
      inputs:
        command: 'restore'
        projects: '**/*.csproj'
        workingDirectory: '/src'
    - task: SonarQubePrepare@4
      inputs:
        SonarQube: 'SonarQube-Dev'
        scannerMode: 'MSBuild'
        projectKey: 'Wiired.Card.PauseManagement'
        projectName: 'Wiired.Card.PauseManagement'
           
    - task: DotNetCoreCLI@2
      inputs:
        command: 'build'
        projects: '**/*.sln'    
    - task: SonarQubeAnalyze@4 

The problem was my CI/CD pipeline is created to build the docker image and and deploy on AKS cluster. When I added sonar analysis my code was actually not getting build as build part was happening in my docker build step. I tried adding MSBuild before my SonarAnalysis step but that did not work and then I tried with DotNetCoreCLI@2 build and my pipeline is working as expected.

1 Like

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