Code duplication exclusions not working as expected

We are trying to exclude types from Sonar’s code duplication check, specifically in this case, the duplicated code is an annotation used to generate open API specs; however, Sonar is still including the types in the duplication metrics and our quality gate is failing because we don’t meet the quality profile requirements.

The glob pattern we are using for code duplication exclusion is

**/Triggers/Http/**/*

  • ALM used - Azure DevOps
  • CI system used - Azure DevOps
  • Scanner:
    sonar.scanner.app=ScannerMSBuild sonar.scanner.mode=dotnet
  • Languages of the repository - C# dotNet
  • Steps to reproduce

See background processor task AZawxZHEsFDSJEdYTb9X

Setting code duplication exclusions via the ADO yaml pipelines eg.

sonar.cdp.exclusions=**/Triggers/Http/**/*

per the online documentation about the accepted glob matching patterns

Defining matching patterns | SonarQube Cloud Documentation

Could you confirm if the global pattern is valid, and or correct for the duplication warnings raised in the background task referenced?

Please let me know if there is any additional info you need, thank you in advance.

Hi,

Did you copy/paste your exclusion? Because there’s a typo in it. Instead of cdp it should be cpd.

The pattern itself looks good, though.

And I should mention that for the SonarScanner for .NET, exclusions aren’t applied during CI-side analysis - so you’ll still see excluded files showing up in the logs as being processed. For the SS4.NET, exclusions are only applied server-side after all the heavy lifting is done.

 
HTH,
Ann

OMG! Yes we did.

Let me try that; Im so embarrassed. Thank you.

1 Like