java.lang.IllegalStateException with SonarScanner

version-info:

  • Gitlab-CI community: 17.7
  • Sonarqube community: 10.7
  • Sonarqube scanner: 11
  • deployment: docker-compose

setup

I’m trying to analyze a Python project with a on-prem version of Gitlab and a on-prem community version of Sonarqube.

issue

5:48:19.414 INFO  Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
15:48:19.417 INFO  Project root configuration file: /builds/misc/autoinstallbuilder/sonar-project.properties
15:48:19.430 INFO  SonarScanner CLI 6.2.1.4610
15:48:19.431 INFO  Java 17.0.12 Amazon.com Inc. (64-bit)
15:48:19.432 INFO  Linux 6.8.0-51-generic amd64
15:48:19.437 DEBUG Scanner max available memory: 978 MB
15:48:19.454 DEBUG uname -m returned 'x86_64'
15:48:19.455 DEBUG Create: /builds/misc/autoinstallbuilder/.sonar/cache
15:48:19.455 INFO  User cache: /builds/misc/autoinstallbuilder/.sonar/cache
15:48:19.455 DEBUG Create: /builds/misc/autoinstallbuilder/.sonar/cache/_tmp
15:48:19.456 DEBUG Using truststore: custom.truststore
15:48:19.935 DEBUG Loaded [1029] system trusted certificates
15:48:20.505 DEBUG --> GET https://sonarqube.brave-vesperia.com/api/v2/analysis/version
15:48:20.624 DEBUG <-- 401 https://sonarqube.brave-vesperia.com/api/v2/analysis/version (119ms, 0-byte body)
15:48:20.625 DEBUG --> GET https://sonarqube.brave-vesperia.com/api/server/version
15:48:20.664 DEBUG <-- 200 https://sonarqube.brave-vesperia.com/api/server/version (38ms, 12-byte body)
15:48:20.667 INFO  JRE provisioning: os[linux], arch[x86_64]
15:48:20.668 DEBUG --> GET https://sonarqube.brave-vesperia.com/api/v2/analysis/jres?os=linux&arch=x86_64
15:48:20.671 DEBUG <-- 401 https://sonarqube.brave-vesperia.com/api/v2/analysis/jres?os=linux&arch=x86_64 (3ms, 0-byte body)
15:48:20.672 INFO  EXECUTION FAILURE
15:48:20.673 INFO  Total time: 1.262s
15:48:20.673 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Error status returned by url [https://sonarqube.brave-vesperia.com/api/v2/analysis/jres?os=linux&arch=x86_64]: 401
	at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:163)
	at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callApi(ScannerHttpClient.java:126)
	at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callRestApi(ScannerHttpClient.java:104)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreMetadata(JavaRunnerFactory.java:159)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreFromServer(JavaRunnerFactory.java:138)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.createRunner(JavaRunnerFactory.java:85)
	at org.sonarsource.scanner.lib.internal.ScannerEngineLauncherFactory.createLauncher(ScannerEngineLauncherFactory.java:53)
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:123)
	at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:63)

The issue seems to be a 401 error code (forbidden) when querying for installed JREs. I don’t understand why this is, since the GET request to the sonarqube version succeeds.

Edit: I noticed that there seems to be a problem calling any URL with the v2 version of the API.

E.g.;

https://sonarqube.brave-vesperia.com/api/v2/analysis/version

yields HTTP Status 401.

Meanwhile:

https://sonarqube.brave-vesperia.com/api/analysis/version

works and yields HTTP Status 200

Is there anything I need to enable in my installation globally? Does sonar-scanner need extra attributes to call the v2 api?

If I run sonar-scanner outside of my gitlab-ci pipeline, everything works fine.

Found the issue. I’ve sett the wrong SONAR_TOKEN. All on me - >Closed

1 Like

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