Relevant Information:
- Azure Devops - yaml pipeline
- ubuntu image
- dotnet scanner
Issue Observed
Our pipeline works as expected using the @2
task versions of sonar.
We recently tried to migrate to version @3
as recommended in our pipeline:
This task is deprecated. Please upgrade to the latest version. For more information, refer to https://docs.sonarsource.com/sonarcloud/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/
However when we update the pipeline to use version 3, the PR is then decorated with every code issue in the repository rather than only analysing new code (like the previous version).
I’ve noticed that this might be an issue with the filepaths. For example the code filepath from v2 would look like: Project/File
however with v3 it is: s/Project/File
where it now looks to be appending the Azure Devops build folder to the path and then not recognising the code as existing.
I’ve updated other repositories that use .NET with windows images and they work fine, so it seems to be an issue when using the updated dotnet scanner alongside ubuntu. I’ve tried this on a couple repos to see if it was specific to the repository but this issue occurs on any using .NET and ubuntu.
Example pipeline:
steps:
- checkout: self
fetchDepth: 0
- script: 'dotnet tool install --global dotnet-coverage'
displayName: 'Install dotnet-coverage tool'
- task: SonarCloudPrepare@3
inputs:
SonarCloud: ****
organization: ****
scannerMode: 'dotnet'
projectKey:****
projectName: ****
extraProperties: |
sonar.cs.vscoveragexml.reportsPaths=s/coverage.xml
- task: UseDotNet@2
inputs:
packageType: sdk
version: '8.x'
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: NuGetToolInstaller@1
displayName: 'Add latest Nuget Tool Installer'
inputs:
checkLatest: true
- task: NuGetAuthenticate@1
- task: NuGetCommand@2
displayName: 'Restore Nuget dependencies'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
includeNuGetOrg: true
verbosityRestore: Detailed
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '$(solution)'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
inputs:
command: 'test'
projects: '**/**.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code Coverage"'
- task: CopyFiles@2
displayName: 'Move Coverage files for formatting'
inputs:
SourceFolder: $(Agent.TempDirectory)
Contents: '**/*.coverage'
TargetFolder: 'coverage'
- task: DotNetCoreCLI@2
displayName: 'Convert Coverage Files to xml for Sonar Analysis'
inputs:
command: 'custom'
custom: 'coverage'
arguments: 'merge *.coverage --recursive --output coverage.xml --output-format xml'
- task: SonarCloudAnalyze@3
inputs:
jdkversion: 'JAVA_HOME_17_X64'
- task: SonarCloudPublish@3
inputs:
pollingTimeoutSec: '300'