SonarScanner not using the java value set in JAVA_HOME_17_X64 for code analysis

Hi guys,

We are using:
SonarQube Enterprise 10.6.0.92116 / SonarScanner CLI 6.1.0.4477

And we are trying to run code analysis on PHP project via Azure DevOps.
Problem that we are facing is that the scanner downloads automatically java and uses it, instead our local java which is set as JAVA_HOME_17_X64 in the Azure task and also on the agent, for the user which runs that job.
It appears that JAVA_HOME_17_X64 is being recognized by the job, nevertheless another java gets downloaded and used, which causes a problem related to certificates:

2024-09-03T12:46:42.9590219Z ##[section]Starting: SQ Analysis
2024-09-03T12:46:42.9593257Z ==============================================================================
2024-09-03T12:46:42.9593351Z Task         : Run Code Analysis
2024-09-03T12:46:42.9593419Z Description  : Run scanner and upload the results to the SonarQube server.
2024-09-03T12:46:42.9593496Z Version      : 6.3.2
2024-09-03T12:46:42.9593543Z Author       : sonarsource
2024-09-03T12:46:42.9593599Z Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarqube-extension-for-azure-devops/)
2024-09-03T12:46:42.9593833Z ==============================================================================
...
2024-09-03T12:46:43.1140679Z ##[debug]jdkversion=JAVA_HOME_17_X64
2024-09-03T12:46:43.1141454Z ##[debug]SONAR_SCANNER_MODE=CLI
2024-09-03T12:46:43.1141948Z ##[debug]SONAR_SERVER_VERSION=10.6.0
2024-09-03T12:46:43.1142421Z ##[debug]JAVA_HOME_17_X64=/usr/lib/jvm/java-17-openjdk-17.0.11.0.9-2.0.1.el8.x86_64
2024-09-03T12:46:43.1146889Z ##[debug]JAVA_HOME_17_X64 was found with value /usr/lib/jvm/java-17-openjdk-17.0.11.0.9-2.0.1.el8.x86_64, will switch to it for Sonar scanner...
2024-09-03T12:46:43.1148276Z ##[debug]JAVA_HOME=/usr/lib/jvm/java-17-openjdk-17.0.11.0.9-2.0.1.el8.x86_64
2024-09-03T12:46:43.1149355Z ##[debug]set JAVA_HOME=/usr/lib/jvm/java-17-openjdk-17.0.11.0.9-2.0.1.el8.x86_64
2024-09-03T12:46:43.1151543Z ##[debug]Processed: ##vso[task.setvariable variable=JAVA_HOME;isOutput=false;issecret=false;]/usr/lib/jvm/java-17-openjdk-17.0.11.0.9-2.0.1.el8.x86_64
...
2024-09-03T12:46:43.1170919Z [command]/xxx/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/6.3.2/sonar-scanner/bin/sonar-scanner -X
2024-09-03T12:46:43.4871421Z 15:46:43.482 INFO  Scanner configuration file: /xxx/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/6.3.2/sonar-scanner/conf/sonar-scanner.properties
2024-09-03T12:46:43.4877812Z 15:46:43.486 INFO  Project root configuration file: NONE
2024-09-03T12:46:43.4977435Z 15:46:43.497 INFO  SonarScanner CLI 6.1.0.4477
2024-09-03T12:46:43.4990044Z 15:46:43.498 INFO  Java 17.0.11 Red Hat, Inc. (64-bit)
2024-09-03T12:46:43.4994531Z 15:46:43.499 INFO  Linux 5.4.17-2136.334.6.1.el8uek.x86_64 amd64
2024-09-03T12:46:43.5000617Z 15:46:43.499 INFO  SONAR_SCANNER_OPTS=
2024-09-03T12:46:43.5061341Z 15:46:43.505 DEBUG Scanner max available memory: 4 GB
2024-09-03T12:46:43.5271201Z 15:46:43.525 DEBUG uname -m returned 'x86_64'
...
2024-09-03T12:46:43.7741613Z 15:46:43.773 DEBUG Loaded [445] system trusted certificates
2024-09-03T12:46:43.9117345Z 15:46:43.910 DEBUG --> GET https://sonarqube.xxx/api/v2/analysis/version
2024-09-03T12:46:44.2827196Z 15:46:44.282 DEBUG <-- 200 https://sonarqube.xxx/api/v2/analysis/version (371ms, 12-byte body)
2024-09-03T12:46:44.2839270Z 15:46:44.283 INFO  JRE provisioning: os[linux], arch[x86_64]
2024-09-03T12:46:44.2854696Z 15:46:44.285 DEBUG --> GET https://sonarqube.xxx/api/v2/analysis/jres?os=linux&arch=x86_64
2024-09-03T12:46:44.3495840Z 15:46:44.349 DEBUG <-- 200 https://sonarqube.xxx/api/v2/analysis/jres?os=linux&arch=x86_64 (63ms, unknown-length body)
2024-09-03T12:46:44.3583847Z 15:46:44.357 DEBUG Executing: /xxx/.sonar/cache/bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz_unzip/jdk-17.0.11+9-jre/bin/java --version
2024-09-03T12:46:44.3942449Z 15:46:44.393 DEBUG openjdk 17.0.11 2024-04-16
2024-09-03T12:46:44.3943036Z 15:46:44.393 DEBUG OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9)
2024-09-03T12:46:44.3943591Z 15:46:44.393 DEBUG OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode, sharing)
2024-09-03T12:46:44.3989787Z 15:46:44.398 DEBUG --> GET https://sonarqube.xxx/api/v2/analysis/engine
2024-09-03T12:46:44.4615201Z 15:46:44.460 DEBUG <-- 200 https://sonarqube.xxx/api/v2/analysis/engine (61ms, unknown-length body)
2024-09-03T12:46:44.4658108Z 15:46:44.465 INFO  Communicating with SonarQube Server 10.6.0.92116
2024-09-03T12:46:44.4670056Z 15:46:44.466 DEBUG Work directory: /xxx/.scannerwork
2024-09-03T12:46:44.4738479Z 15:46:44.473 DEBUG **Executing: /xxx/.sonar/cache/bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz_unzip/jdk-17.0.11+9-jre/bin/java -jar /xxx/.sonar/cache/a86f18d343a1c4d6d5e36f4282340f26a6298dcf88ccf2d9b1dcdd68e4230954/scanner-enterprise-10.6.0.92116-all.jar**

Do you have any ideas what is causing that behavior and how we can fix it?

Thanks!

Hi,

To use the existing JRE installation you can disable the JRE auto-provisioning in SonarScanner by setting the property sonar.scanner.skipJreProvisioning or the environment variable SONAR_SCANNER_SKIP_JRE_PROVISIONING to true.

1 Like

Thanks Felipe,

That did the job for us, appreciate it.

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