Sonarcloud excluding random files and folders

  • ALM used - Azure DevOps

  • CI system used - Azure DevOps

  • Scanner command used when applicable (private details masked) - NA

  • Languages of the repository - C#, HTML, javascript

  • Error observed
    Sonarcloud is randomly excluding some files from analysis. a folder has 2 c# files which should be analyzed - its analyzing only one. For example, i have these 2 files

  1. PreValidateAccount.cs - included in analysis
  2. AccountPlugin.cs - excluded from analysis.

Its also excluding random folders from analysis. This has resulted in only 10% of the code (13k lines) being analyzed against 130k lines which are part of the visual studio solution.
When the same was run against an on premise sonarcube it included all of those files for analysis.

  • Steps to reproduce - Run the azure pipeline against develop branch. Azure Pipeline has following tasks
Use NuGet 4.4.1 task
- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.4.1'
    versionSpec: 4.4.1

Nuget restore task
- task: NuGetCommand@2
  displayName: 'NuGet restore'
    restoreSolution: 'foldername/VisualStudioSolutionName.sln'
    feedsToUse: config
    nugetConfigPath: 'foldername/nuget.config'
Prepare analysis on sonarcloud task

- task: SonarSource.sonarcloud.<<task_GUID>>.SonarCloudPrepare@1
  displayName: 'Prepare analysis on SonarCloud'
    SonarCloud: SonarCloud
    organization: 'OrganisationName'
    projectKey: 'OrganisationName_ProjectName'
    projectName: 'ProjectName'
    extraProperties: |
     # Additional properties that will be passed to the scanner, 
     # Put one key=value per line, example:
     # sonar.exclusions=**/*.bin
Build Solution task

#Your build pipeline references an undefined variable named ‘BuildPlatform’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See
#Your build pipeline references an undefined variable named ‘BuildConfiguration’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See

- task: VSBuild@1
  displayName: 'Build solution foldername/VisualStudioSolutionName.sln'
    solution: 'foldername/VisualStudioSolutionName.sln'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\" /p:CreatePackageOnPublish=True /p:OutputPath=bin'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
Run code analysis task

- task: SonarSource.sonarcloud.<<task_GUID>>.SonarCloudAnalyze@1
  displayName: 'Run Code Analysis'
  • Potential workaround - none

Hi @rahulpatil , welcome to the community.

You can activate debug logs on your build execution by setting up system.debug=true pipeline variable.

With that, our Run Code Analysis task will dump the generated file in the logs directly. You can then check if the missing files are present or not here across mulitple executions.

This is a first step, let us know the outcome.


Hi @mickaelcaro

thank you for your response, the debug logs show both the included and excluded files. But the difference is, it shows the following type of log only for included files. similar line is missing for excluded files.

2021-08-11T14:40:12.5363750Z 14:40:12.353 DEBUG: Blame file <filepath>/PreValidateAccount.cs

Here are all relevant lines from the log focusing on the AccountHandler project.
The file AccountPlugin.cs is excluded from the analysis by sonarcloud and PreValidateAccount.cs is included in the analysis.

Please let me know how I can send the actual log file to you privately, I cant post it here for privacy reasons.

thank you

Issue was about analyse delta code (for new code period and branch) where this file was not present.

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