Failed to parse JSON in SONARQUBE_SCANNER_PARAMS environment variable

Must-share information (formatted with Markdown):

  • I am using sonarqube 10.3 version
  • sonarqube is deployed using zip
  • I am using azure devops pipeline to analyze project which is in C# as well as typescript.
  • I am using 2 scanners in the azure devops pipeline, here is my code :
variables:
SONARQUBE_SCANNER_PARAMS_CSHARP: '{"sonar.language": "cs"}'
 SONARQUBE_SCANNER_PARAMS_TYPESCRIPT: '{"sonar.language": "ts"}'

- task: SonarQubePrepare@5
      inputs:
        SonarQube: 'sonarqube'
        scannerMode: 'MSBuild'
        projectKey: 'xxxxxxx'
        projectName: 'Atlas'
       
    
    - task: DotNetCoreCLI@2
      displayName: Build
      inputs:
        projects: '$(ApiProjectName).csproj'
        arguments: '--configuration $(buildConfiguration)'

    - script: 'echo "##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS]$(SONARQUBE_SCANNER_PARAMS_CSHARP)"'
      displayName: 'Set SONARQUBE_SCANNER_PARAMS for C#'    
    
    - task: SonarQubeAnalyze@5
      inputs:
        jdkversion: 'JAVA_HOME_17_X64'

    
    - task: SonarQubePublish@5
      inputs:
        pollingTimeoutSec: '300'
    - task: SonarQubePrepare@5
      inputs:
        SonarQube: 'sonarqube'
        scannerMode: 'CLI'
        configMode: 'manual'
        cliProjectKey: 'xxxxxxxxxxx'
             

    - script: 'echo "##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS]$(SONARQUBE_SCANNER_PARAMS_TYPESCRIPT)"'
     displayName: 'Set SONARQUBE_SCANNER_PARAMS for TypeScript'
    - task: SonarQubeAnalyze@5
      inputs:
        jdkversion: 'JAVA_HOME_17_X64'

, but getting error like below :

##[error]at org.sonarsource.scanner.cli.Conf.loadEnvironmentProperties(Conf.java:78)

at org.sonarsource.scanner.cli.Conf.loadGlobalProperties(Conf.java:85)

at org.sonarsource.scanner.cli.Conf.properties(Conf.java:59)

at org.sonarsource.scanner.cli.Main.execute(Main.java:70)

at org.sonarsource.scanner.cli.Main.main(Main.java:62)

at org.sonarsource.scanner.cli.Conf.loadEnvironmentProperties(Conf.java:78)

at org.sonarsource.scanner.cli.Conf.loadGlobalProperties(Conf.java:85)

at org.sonarsource.scanner.cli.Conf.properties(Conf.java:59)

at org.sonarsource.scanner.cli.Main.execute(Main.java:70)

at org.sonarsource.scanner.cli.Main.main(Main.java:62)

##[error]Caused by: org.sonarsource.scanner.api.internal.shaded.minimaljson.ParseException: Expected name at 1:2

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.error(JsonParser.java:490)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.expected(JsonParser.java:486)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readName(JsonParser.java:259)

Caused by: org.sonarsource.scanner.api.internal.shaded.minimaljson.ParseException: Expected name at 1:2

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.error(JsonParser.java:490)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.expected(JsonParser.java:486)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readName(JsonParser.java:259)

##[error]at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readObject(JsonParser.java:238)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readValue(JsonParser.java:177)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:152)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:91)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.Json.parse(Json.java:295)

at org.sonarsource.scanner.api.Utils.loadEnvironmentProperties(Utils.java:54)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readObject(JsonParser.java:238)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readValue(JsonParser.java:177)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:152)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:91)

at org.sonarsource.scanner.api.internal.shaded.minimaljson.Json.parse(Json.java:295)

at org.sonarsource.scanner.api.Utils.loadEnvironmentProperties(Utils.java:54)

##[error]... 5 more

ERROR:

... 5 more

ERROR:

##[error]The SonarScanner did not complete successfully

The SonarScanner did not complete successfully

##[error]10:36:49.292 Post-processing failed. Exit code: 1

10:36:49.292 Post-processing failed. Exit code: 1

##[error]The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 1

Please suggest something so that project can get analyzed in both c# and typescript language.

Hi,

The initial line is missing from that error & it would be helpful (I think) to have it. In fact, can we just have that full log?

As a side note,

sonar.language hasn’t had any effect for years and years now. All analyses are multi-language by default.

 
Ann

Okay sure, so here is the complete log of azure devops pipeline step:

1. ##[error]at org.sonarsource.scanner.cli.Conf.loadEnvironmentProperties(Conf.java:78)
    at org.sonarsource.scanner.cli.Conf.loadGlobalProperties(Conf.java:85)
    at org.sonarsource.scanner.cli.Conf.properties(Conf.java:59)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:70)
    at org.sonarsource.scanner.cli.Main.main(Main.java:62)
    at org.sonarsource.scanner.cli.Conf.loadEnvironmentProperties(Conf.java:78)
    at org.sonarsource.scanner.cli.Conf.loadGlobalProperties(Conf.java:85)
    at org.sonarsource.scanner.cli.Conf.properties(Conf.java:59)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:70)
    at org.sonarsource.scanner.cli.Main.main(Main.java:62)
##[error]Caused by: org.sonarsource.scanner.api.internal.shaded.minimaljson.ParseException: Expected name at 1:2
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.error(JsonParser.java:490)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.expected(JsonParser.java:486)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readName(JsonParser.java:259)
Caused by: org.sonarsource.scanner.api.internal.shaded.minimaljson.ParseException: Expected name at 1:2
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.error(JsonParser.java:490)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.expected(JsonParser.java:486)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readName(JsonParser.java:259)
##[error]at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readObject(JsonParser.java:238)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readValue(JsonParser.java:177)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:152)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:91)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.Json.parse(Json.java:295)
    at org.sonarsource.scanner.api.Utils.loadEnvironmentProperties(Utils.java:54)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readObject(JsonParser.java:238)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readValue(JsonParser.java:177)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:152)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:91)
    at org.sonarsource.scanner.api.internal.shaded.minimaljson.Json.parse(Json.java:295)
    at org.sonarsource.scanner.api.Utils.loadEnvironmentProperties(Utils.java:54)
##[error]... 5 more
ERROR:
... 5 more
ERROR:
##[error]The SonarScanner did not complete successfully
The SonarScanner did not complete successfully
##[error]10:36:49.292 Post-processing failed. Exit code: 1
10:36:49.292 Post-processing failed. Exit code: 1
##[error]The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 1
Finishing: SonarQubeAnalyze

so, ultimately our goal is to analyze both c# and typescript code which is in same branch and it running through the same pipeline.

Hi,

Can we have the full log? As I stated previously, the initial line is missing from the error, and it would also be useful to know where in analysis the error occurred, as well as the analysis context. Thus, we need the full log.

 
Thx,
Ann

2024-01-10T10:36:48.1225404Z ##[section]Starting: SonarQubeAnalyze
2024-01-10T10:36:48.1229168Z ==============================================================================
2024-01-10T10:36:48.1229313Z Task         : Run Code Analysis
2024-01-10T10:36:48.1229413Z Description  : Run scanner and upload the results to the SonarQube server.
2024-01-10T10:36:48.1229598Z Version      : 5.18.4
2024-01-10T10:36:48.1229671Z Author       : sonarsource
2024-01-10T10:36:48.1229753Z Help         : Version: 5.18.4. 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)
2024-01-10T10:36:48.1230045Z ==============================================================================
2024-01-10T10:36:48.5308921Z [command]/opt/hostedtoolcache/dotnet/dotnet /home/vsts/work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/5.18.4/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll end
2024-01-10T10:36:48.6069685Z SonarScanner for MSBuild 5.15
2024-01-10T10:36:48.6073889Z Using the .NET Core version of the Scanner for MSBuild
2024-01-10T10:36:48.6845620Z Post-processing started.
2024-01-10T10:36:48.7514928Z 10:36:48.75  10:36:48.745  10:36:48.745  WARNING: Failed to parse properties from the environment variable 'SONARQUBE_SCANNER_PARAMS' because 'Invalid JavaScript property identifier character: .. Path '', line 1, position 6.'.
2024-01-10T10:36:48.7788357Z 10:36:48.778  10:36:48.778  WARNING: Failed to parse properties from the environment variable 'SONARQUBE_SCANNER_PARAMS' because 'Invalid JavaScript property identifier character: .. Path '', line 1, position 6.'.
2024-01-10T10:36:48.8767272Z WARNING: Failed to parse properties from the environment variable 'SONARQUBE_SCANNER_PARAMS' because 'Invalid JavaScript property identifier character: .. Path '', line 1, position 6.'.
2024-01-10T10:36:48.8769683Z Calling the SonarScanner CLI...
2024-01-10T10:36:49.1947511Z INFO: ------------------------------------------------------------------------
2024-01-10T10:36:49.1953973Z INFO: EXECUTION FAILURE
2024-01-10T10:36:49.1958137Z INFO: ------------------------------------------------------------------------
2024-01-10T10:36:49.2286608Z INFO: Total time: 0.030s
2024-01-10T10:36:49.2659604Z INFO: Final Memory: 1M/8M
2024-01-10T10:36:49.2674949Z INFO: ------------------------------------------------------------------------
2024-01-10T10:36:49.2753856Z ##[error]ERROR: Error during SonarScanner execution
2024-01-10T10:36:49.2769077Z ERROR: Error during SonarScanner execution
2024-01-10T10:36:49.2770047Z ##[error]java.lang.IllegalStateException: Failed to parse JSON in SONARQUBE_SCANNER_PARAMS environment variable
2024-01-10T10:36:49.2770694Z java.lang.IllegalStateException: Failed to parse JSON in SONARQUBE_SCANNER_PARAMS environment variable
2024-01-10T10:36:49.2771721Z ##[error]at org.sonarsource.scanner.api.Utils.loadEnvironmentProperties(Utils.java:65)
2024-01-10T10:36:49.2772307Z 	at org.sonarsource.scanner.api.Utils.loadEnvironmentProperties(Utils.java:65)
2024-01-10T10:36:49.2773557Z ##[error]at org.sonarsource.scanner.cli.Conf.loadEnvironmentProperties(Conf.java:78)
	at org.sonarsource.scanner.cli.Conf.loadGlobalProperties(Conf.java:85)
	at org.sonarsource.scanner.cli.Conf.properties(Conf.java:59)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:70)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
2024-01-10T10:36:49.2774455Z 	at org.sonarsource.scanner.cli.Conf.loadEnvironmentProperties(Conf.java:78)
2024-01-10T10:36:49.2774772Z 	at org.sonarsource.scanner.cli.Conf.loadGlobalProperties(Conf.java:85)
2024-01-10T10:36:49.2775082Z 	at org.sonarsource.scanner.cli.Conf.properties(Conf.java:59)
2024-01-10T10:36:49.2775375Z 	at org.sonarsource.scanner.cli.Main.execute(Main.java:70)
2024-01-10T10:36:49.2775660Z 	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
2024-01-10T10:36:49.2777329Z ##[error]Caused by: org.sonarsource.scanner.api.internal.shaded.minimaljson.ParseException: Expected name at 1:2
	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.error(JsonParser.java:490)
	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.expected(JsonParser.java:486)
	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readName(JsonParser.java:259)
2024-01-10T10:36:49.2778529Z Caused by: org.sonarsource.scanner.api.internal.shaded.minimaljson.ParseException: Expected name at 1:2
2024-01-10T10:36:49.2778905Z 	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.error(JsonParser.java:490)
2024-01-10T10:36:49.2779302Z 	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.expected(JsonParser.java:486)
2024-01-10T10:36:49.2779684Z 	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readName(JsonParser.java:259)
2024-01-10T10:36:49.2781529Z ##[error]at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readObject(JsonParser.java:238)
	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readValue(JsonParser.java:177)
	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:152)
	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:91)
	at org.sonarsource.scanner.api.internal.shaded.minimaljson.Json.parse(Json.java:295)
	at org.sonarsource.scanner.api.Utils.loadEnvironmentProperties(Utils.java:54)
2024-01-10T10:36:49.2782809Z 	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readObject(JsonParser.java:238)
2024-01-10T10:36:49.2783194Z 	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.readValue(JsonParser.java:177)
2024-01-10T10:36:49.2783584Z 	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:152)
2024-01-10T10:36:49.2783964Z 	at org.sonarsource.scanner.api.internal.shaded.minimaljson.JsonParser.parse(JsonParser.java:91)
2024-01-10T10:36:49.2784336Z 	at org.sonarsource.scanner.api.internal.shaded.minimaljson.Json.parse(Json.java:295)
2024-01-10T10:36:49.2784674Z 	at org.sonarsource.scanner.api.Utils.loadEnvironmentProperties(Utils.java:54)
2024-01-10T10:36:49.2785119Z ##[error]... 5 more
ERROR:
2024-01-10T10:36:49.2785514Z 	... 5 more
2024-01-10T10:36:49.2785668Z ERROR: 
2024-01-10T10:36:49.2932283Z ##[error]The SonarScanner did not complete successfully
2024-01-10T10:36:49.2933012Z The SonarScanner did not complete successfully
2024-01-10T10:36:49.2933497Z ##[error]10:36:49.292  Post-processing failed. Exit code: 1
2024-01-10T10:36:49.2934566Z 10:36:49.292  Post-processing failed. Exit code: 1
2024-01-10T10:36:49.3067612Z ##[error]The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 1
2024-01-10T10:36:49.3092691Z ##[section]Finishing: SonarQubeAnalyze

Hi,

Thanks for the log.

Could you echo the SONARQUBE_SCANNER_PARAMS envvar so we can see what’s in it?

Could you also provide a debug log?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Thx,
Ann