Reputation: 165
I have setup my Sonar server on my AKS (Azure Kubernetes 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: MSBuild@1
inputs:
solution: '/*.sln'
restoreNugetPackages: true
clean: true
- task: SonarQubeAnalyze@4
Upvotes: 0
Views: 2317
Reputation: 165
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.
Upvotes: 1
Reputation: 4896
Looking at the error, you are using SonarQube to analyze a legacy .NET Framework application but your SonarQube requires MSBuild of v14.0.25420.1 or later.
This MSBuild version is the one that comes with Visual Studio 2015 update 15.6.1 or later. Therefore your solution and your application must use Visual Studio at least Visual Studio 2015 update 15.6.1 or the recommended way is to use Visual Studio 2019 update 16.7.1 or later.
The reason why I suggest to use Visual Studio 2019 is because Microsoft may end support for Visual Studio 2015 in Azure DevOps soon, and currently Visual Studio 2015 is not supported anymore. Visual Studio 2017 is still supported, but its support will end next year.
Therefore please upgrade your app to use target of .NET Framework v4.7.2 or later and develop it using Visual Studio 2017 with latest update (currently 15.9.26) or use Visual Studio 2019.
Upvotes: 0