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:
The project has not been built - the project must be built in between the begin and end steps
An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
The begin, build and end steps have not all been launched from the same folder
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
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 ?
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
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.