ERROR: Caused by: Property: 'sonar.exclusions' doesn't contain a valid CSV value:

I am adding to my Azure DevOps build pipeline the following sonar tasks:

  • Prepare analysis on SonarCloud
  • Run Code Analysis
  • Publish Quality Gate Result

It is of this way in the azure-pipelines.acr.yml
(These are only the SonarCloud related tasks just in case)

steps:
- task: SonarCloudPrepare@1
  displayName: 'Prepare analysis on SonarCloud'
  inputs:
    SonarCloud: 'My-SonarCloud-Instance'
    organization: 'my-org'
    scannerMode: 'MSBuild'
    projectKey: 'my-key'
    projectName: 'my-project-name'
    extraProperties:
      # Additional properties that will be passed to the scanner,
      # Put one key=value per line, example:
      sonar.exclusions="**/bin/**/*,**/obj/**/*,**/Startup.cs,**/Program.cs"
      sonar.coverage.exclusions="**/*UnitTests*"
      sonar.cs.opencover.reportsPaths="**\*.opencover.xml"'
  continueOnError: true

- task: DotNetCoreCLI@2
  displayName: 'Build solution'
  inputs:
    command: 'build'
    # projects: '**/*.csproj'
    projects: '*.sln'
    # arguments: '--configuration $(BuildConfiguration)'
    arguments: '--configuration Release'

- task: DotNetCoreCLI@2
  displayName: 'Test'
  inputs:
    command: 'test'
    projects: '**/*.UnitTests.csproj'
    # projects: '*UnitTests/*.csproj'
    # arguments: '--no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover%2clcov /v:q /p:Exclude="[xunit*]*"'
    arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
    publishTestResults: false

- task: SonarCloudAnalyze@1
  displayName: 'Run Code Analysis'
  continueOnError: true

- task: SonarCloudPublish@1
  displayName: 'Publish Quality Gate Result'
  inputs:
    pollingTimeoutSec: '300'

And when I go to the log of the build pipeline I get the following in the Run Code Analysis task:

##[section]Starting: Run Code Analysis
==============================================================================
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 1.6.3
Author       : sonarsource
Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
[command]/usr/bin/dotnet /home/vsts/work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/1.6.3/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll end
SonarScanner for MSBuild 4.6.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
WARNING: File '/home/vsts/.nuget/packages/microsoft.net.test.sdk/16.0.1/build/netcoreapp1.0/Microsoft.NET.Test.Sdk.Program.cs' is not located under the root directory '/home/vsts/work/1/s' and will not be analyzed.
WARNING: File '/home/vsts/.nuget/packages/xunit.runner.visualstudio/2.4.1/build/netcoreapp1.0/xunit.runner.visualstudio.dotnetcore.testadapter.dll' is not located under the root directory '/home/vsts/work/1/s' and will not be analyzed.
WARNING: File '/home/vsts/.nuget/packages/xunit.runner.visualstudio/2.4.1/build/netcoreapp1.0/xunit.runner.reporters.netcoreapp10.dll' is not located under the root directory '/home/vsts/work/1/s' and will not be analyzed.
WARNING: File '/home/vsts/.nuget/packages/xunit.runner.visualstudio/2.4.1/build/netcoreapp1.0/xunit.runner.utility.netcoreapp10.dll' is not located under the root directory '/home/vsts/work/1/s' and will not be analyzed.
Calling the SonarQube Scanner...
INFO: Scanner configuration file: /home/vsts/work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/1.6.3/dotnet-sonar-scanner-msbuild/sonar-scanner-3.3.0.1492/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/vsts/work/1/.sonarqube/out/sonar-project.properties
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_212 Azul Systems, Inc. (64-bit)
INFO: Linux 4.15.0-1045-azure amd64
INFO: User cache: /home/vsts/.sonar/cache
INFO: SonarQube server 7.8.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=260ms
INFO: Server id: BD367519-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /home/vsts/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=95ms
INFO: Load/download plugins (done) | time=15409ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=71ms
INFO: Project key: My-Key
INFO: Base dir: /home/vsts/work/1/s
INFO: Working dir: /home/vsts/work/1/.sonarqube/out/.sonar
INFO: Load project settings for component key: 'My-Key'
INFO: Load project settings for component key: 'My-Key' (done) | time=63ms
INFO: Load project branches
INFO: Load project branches (done) | time=64ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=35ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=2ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=68ms
INFO: Detected Azure DevOps
INFO: Load active rules
INFO: Load active rules (done) | time=1586ms
INFO: Organization key: admin46120
INFO: Branch name: Deployments, type: short living
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 22.596s
INFO: Final Memory: 27M/169M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarQube Scanner execution
ERROR: Error during SonarQube Scanner execution
##[error]ERROR: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectFileIndexer
ERROR: Caused by: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectExclusionFilters
ERROR: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectFileIndexer
ERROR: Caused by: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectExclusionFilters
##[error]ERROR: Caused by: Property: 'sonar.exclusions' doesn't contain a valid CSV value: '"**/bin/**/*,**/obj/**/*,**/Startup.cs,**/Program.cs" sonar.coverage.exclusions="**/*UnitTests*" sonar.cs.opencover.reportsPaths="**\*.opencover.xml"''
ERROR: Caused by: (line 1) invalid char between encapsulated token and delimiter
ERROR:
ERROR: Caused by: Property: 'sonar.exclusions' doesn't contain a valid CSV value: '"**/bin/**/*,**/obj/**/*,**/Startup.cs,**/Program.cs" sonar.coverage.exclusions="**/*UnitTests*" sonar.cs.opencover.reportsPaths="**\*.opencover.xml"''
ERROR: Caused by: (line 1) invalid char between encapsulated token and delimiter
ERROR: 
##[error]The SonarQube Scanner did not complete successfully
The SonarQube Scanner did not complete successfully
##[error]15:27:59.675  Post-processing failed. Exit code: 1
15:27:59.675  Post-processing failed. Exit code: 1
##[error]/usr/bin/dotnet failed with return code: 1
##[section]Finishing: Run Code Analysis

By the way, the output of my Test task was the following

##[section]Starting: Test
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
Version      : 2.151.1
Author       : Microsoft Corporation
Help         : https://go.microsoft.com/fwlink/?linkid=832194
==============================================================================
##[warning]Project file(s) matching the specified pattern were not found.
##[section]Finishing: Test

This Test task is executing it before to my Running Code Analysis task
Maybe it is the cause of my situation? I mean, the test command has not found the test project and this step was skipped.

Hi,

You have an extra quote at the end of the “sonar.cs.opencover.reportsPaths” property value

Could you remove it and test again ?

Thanks,

1 Like

I’ve removed the extra quote and the output is the same

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 28.281s
INFO: Final Memory: 30M/278M
INFO: ------------------------------------------------------------------------
##[error]ERROR: Error during SonarQube Scanner execution
ERROR: Error during SonarQube Scanner execution
##[error]ERROR: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectFileIndexer
ERROR: Caused by: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectExclusionFilters
ERROR: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectFileIndexer
ERROR: Caused by: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectExclusionFilters
##[error]ERROR: Caused by: Property: 'sonar.exclusions' doesn't contain a valid CSV value: '"**/bin/**/*,**/obj/**/*,**/Startup.cs,**/Program.cs" sonar.coverage.exclusions="**/*UnitTests*" sonar.cs.opencover.reportsPaths="**\*.opencover.xml"'
ERROR: Caused by: (line 1) invalid char between encapsulated token and delimiter
ERROR:
ERROR: Caused by: Property: 'sonar.exclusions' doesn't contain a valid CSV value: '"**/bin/**/*,**/obj/**/*,**/Startup.cs,**/Program.cs" sonar.coverage.exclusions="**/*UnitTests*" sonar.cs.opencover.reportsPaths="**\*.opencover.xml"'
ERROR: Caused by: (line 1) invalid char between encapsulated token and delimiter
ERROR: 
##[error]The SonarQube Scanner did not complete successfully
The SonarQube Scanner did not complete successfully
##[error]06:36:44.848  Post-processing failed. Exit code: 1
06:36:44.848  Post-processing failed. Exit code: 1
##[error]/usr/bin/dotnet failed with return code: 1
##[section]Finishing: Run Code Analysis

Ok, thanks, so can you try then without any double quotes around each property value ?

I have changed some specific small things according to your suggestions:

In the SonarCloudPrepare@1 task, I’ve removed the double quotes such as you told me in the extraProperties attribute, but also, I did need specify the correct Endpoint, because I had the connection name and not the URL endpoint

In summary, the SonarCloud tasks finally are the following:

steps:
- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'https://sonarcloud.io'
    organization: 'my-organization'
    scannerMode: 'MSBuild'
    projectKey: 'my-key'
    projectName: 'my-project-name'
    extraProperties:
      sonar.exclusions=**/bin/**/*%2c**/obj/**/*%2c**/Startup.cs%2c**/Program.cs
      sonar.coverage.exclusions=**/*UnitTests*
      sonar.cs.opencover.reportsPaths=**\*.opencover.xml
  continueOnError: true

- task: DotNetCoreCLI@2
  displayName: 'Build solution'
  inputs:
    command: 'build'
    # projects: '**/*.csproj'
    projects: '*.sln'
    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: 'Test'
  inputs:
    command: 'test'
    projects: '**/*.UnitTests.csproj'
    # projects: '*UnitTests/*.csproj'
    arguments: '--no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover%2clcov /v:q /p:Exclude="[xunit*]*"'
    publishTestResults: false

- task: SonarCloudAnalyze@1
  displayName: 'Run Code Analysis'
  continueOnError: true

- task: SonarCloudPublish@1
  displayName: 'Publish Quality Gate Result'
  inputs:
    pollingTimeoutSec: '300'

And the build process it’s works