Azure Devops Extension (v3) Recognises all code as new code

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'

Hi @RenLau,

Thanks for reporting the issue. It seems that the sonar.projectBaseDir path detection is wrong when running on AzureDevOps on Unix-based systems.

I have created an issue for this and I’m working on a fix. You can follow the progress here: [SCAN4NET-147] - Jira

Hi Lauren,

I’ve fixed the issue with the path detection and did a release. The Azure Extension will be probably released next week.

Until the extension is released you can try the fix by configuring the pipeline to use the latest scanner version.

You can do so using:

- task: SonarCloudPrepare@3
  inputs:
    SonarCloud: '<>'
    organization: '<>'
    scannerMode: 'dotnet'
    msBuildVersion: '9.0.1.102776'
    projectKey: '<>'
    projectName: '<>'

Please let me know if this is fixing the problem for you.

2 Likes

Hi Costin,

I can confirm that we were also suffering from this issue and your fix in the msBuildVersion stated above does solve our problem.

Are you able to advise when this new version of the SonarCloud Azure DevOps tasks will be released? :slight_smile:

2 Likes

Hi,

Thanks for the update. I’m sorry but I cannot give a precise ETA for the release. To the best of my knowledge, I hope we will have a new version early next week.

1 Like

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