Must-share information (formatted with Markdown):
- which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
- SonarQube Developer 10.4.1
- how is SonarQube deployed: zip, Docker, Helm
- Zip deploy
- what are you trying to achieve
- Analyze solution with both C# and C++ code as part of the Azure DevOps CI pipeline (in YML)
- This needs to function on our own hosted build agents, we do not use the Microsoft hosted build agents.
- what have you tried so far to achieve this
- I have used the documentation at SonarQube Docs and the SonarCloud example on github: windows-msbuild-dotnet-cpp-azure-sc to build my yml pipeline.
I am having an issue with analysis of a project with both C# and C++, after following the documentation linked above i was able to get the project building successfully via MSBuild, running though the build wrapper downloaded from our SonarQube server. The build output is as expected, and the logs from the build stage of the pipeline show that SonarQube is detecting both the C++ and C# files to be analyzed.
However when i get to the SonarQubeAnalyze@5 task, I get the following error:
##[error]java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed.
Checking the build-wrapper.log file there is an error near the end, which may be relevant but I donât really know how to interpret this log. The only ERROR is: ERROR: error getting long path name: 123
Here are the relevant parts of the build pipeline YML showing the prepare, download of wrapper, build, test and analyze tasks.
- task: SonarQubePrepare@5
displayName: 'Prepare SonarQube - With Tests'
inputs:
SonarQube: 'SonarQube Server'
scannerMode: 'MSBuild'
configMode: 'manual'
projectKey: '$(Build.Repository.Name)'
projectName: '$(Build.Repository.Name)'
projectVersion: '$(build.buildnumber)'
extraProperties: |
sonar.exclusions=**/Startup.cs,**/Program.cs,**/BaseController.cs,**/HeartBeatController.cs
sonar.cs.vstest.reportsPaths=$(testOutputDirectory)/*.trx
sonar.coverageReportPaths=$(testOutputDirectory)/mergedcoveragereport/SonarQube.xml
sonar.coverage.exclusions=**/Migrations/*.cs,**/*Tests*/**/*
sonar.cpd.exclusions=**/Migrations/*.cs,**/*Tests*/**/*
sonar.cfamily.build-wrapper-output=$(Pipeline.Workspace)\build_wrapper_output_directory
sonar.verbose=true
- pwsh: |
curl --create-dirs -sSLo $HOME\.sonar\build-wrapper-win-x86.zip ${{variables.BUILD_WRAPPER_DOWNLOAD_URL}}
Expand-Archive $HOME\.sonar\build-wrapper-win-x86.zip -DestinationPath $HOME\.sonar\ -Force
displayName: Download and install build wrapper
- pwsh: |
$msbuild = vswhere -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | select-object -first 1
& $msbuild $(solutionFileName) /t:restore /p:Configuration=$(buildConfiguration) /p:Platform=$(buildPlatform)
& "$HOME\.sonar\build-wrapper-win-x86\build-wrapper-win-x86-64.exe" --out-dir $(Pipeline.Workspace)\build_wrapper_output_directory $msbuild $(solutionFileName) /p:Configuration=$(buildConfiguration) /p:Version=$(Build.BuildNumber) /p:AssemblyVersion=$(Build.BuildNumber) /p:FileVersion=$(Build.BuildNumber) /p:Platform=$(buildPlatform) /t:Rebuild /nodeReuse:False
workingDirectory: .
displayName: Build in build-wrapper
- task: DotNetCoreCLI@2
displayName: "dotnet test"
inputs:
command: 'test'
publishTestResults: true
projects: '**/*Tests.csproj'
arguments: '--no-restore --no-build --configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput="$(testOutputDirectory)/" /p:MergeWith="$(testOutputDirectory)/coverage.json" /p:CoverletOutputFormat="cobertura%2cjson"'
env:
DOTNET_MULTILEVEL_LOOKUP: 1
- task: reportgenerator@4
inputs:
reports: '$(testOutputDirectory)/coverage.cobertura.xml'
targetdir: '$(testOutputDirectory)/mergedcoveragereport'
reporttypes: 'Cobertura;SonarQube'
assemblyfilters: '-*Tests*'
filefilters: '-*/Migrations/*.cs'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(testOutputDirectory)/mergedcoveragereport/Cobertura.xml'
- task: SonarQubeAnalyze@5
displayName: 'SonarQube Analyze'
- task: SonarQubePublish@5
displayName: 'SonarQube Publish'
inputs:
pollingTimeoutSec: '300'