I’m trying to add sonar analysis to Jenkins pipelines.
I’m using the npm package @sonar/scanner
and when the pipeline goes through, it tries to auto-provision a JRE.
The JRE is extracted in the following directory:
/home/jenkins/.sonar/cache/4086cc7cb2d9e7810141f255063caad10a8a018db5e6b47fa5394c506ab65bff/OpenJDK17U-jre_x64_linux_hotspot_17.0.13_11.tar.gz_extracted/jdk-17.0.13+11-jre/bin
but the scanner tries to spawn a process at this path /home/jenkins/.sonar/cache/4086cc7cb2d9e7810141f255063caad10a8a018db5e6b47fa5394c506ab65bff/OpenJDK17U-jre_x64_linux_hotspot_17.0.13_11.tar.gz_unzip/jdk-17.0.13+11-jre/bin
and it fails.
The difference that the JRE is extracted in a dir ending with _extracted but the npm package tries to execute java on a dir ending with _unzip and the pipeline fails with the following error:
12:14:46 > sonar-scanner -Dsonar.token=**** -Dsonar.branch.name=**************************
12:14:46
12:14:47 [INFO] Bootstrapper: Retrieving info from "package.json" file
12:14:47 [INFO] Bootstrapper: Platform: linux x64
12:14:47 [INFO] Bootstrapper: Server URL: http://sonar.**********************
12:14:47 [INFO] Bootstrapper: Version: 4.2.8
12:14:47 [INFO] Bootstrapper: SonarQube server version: 2025.1.0
12:14:47 [INFO] Bootstrapper: JRE provisioning is supported
12:14:47 [INFO] Bootstrapper: Using JRE from the cache
12:14:48 node:events:496
12:14:48 throw er; // Unhandled 'error' event
12:14:48 ^
12:14:48
12:14:48 Error: spawn /home/****/.sonar/cache/4086cc7cb2d9e7810141f255063caad10a8a018db5e6b47fa5394c506ab65bff/OpenJDK17U-jre_x64_linux_hotspot_17.0.13_11.tar.gz_unzip/jdk-17.0.13+11-jre/bin/java ENOENT
12:14:48 at ChildProcess._handle.onexit (node:internal/child_process:286:19)
12:14:48 at onErrorNT (node:internal/child_process:484:16)
12:14:48 at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
12:14:48 Emitted 'error' event on ChildProcess instance at:
12:14:48 at ChildProcess._handle.onexit (node:internal/child_process:292:12)
12:14:48 at onErrorNT (node:internal/child_process:484:16)
12:14:48 at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
12:14:48 errno: -2,
12:14:48 code: 'ENOENT',
12:14:48 syscall: 'spawn /home/****/.sonar/cache/4086cc7cb2d9e7810141f255063caad10a8a018db5e6b47fa5394c506ab65bff/OpenJDK17U-jre_x64_linux_hotspot_17.0.13_11.tar.gz_unzip/jdk-17.0.13+11-jre/bin/java',
12:14:48 path: '/home/****/.sonar/cache/4086cc7cb2d9e7810141f255063caad10a8a018db5e6b47fa5394c506ab65bff/OpenJDK17U-jre_x64_linux_hotspot_17.0.13_11.tar.gz_unzip/jdk-17.0.13+11-jre/bin/java',
12:14:48 spawnargs: [
12:14:48 '-jar',
12:14:48 '/home/****/.sonar/cache/3885425e84e5b5a71238840fddb950b86885f3e07f700e8d35726105764011c1/scanner-developer-2025.1.0.102418-all.jar'
12:14:48 ]
12:14:48 }