Getting $ sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}" bash: line 154: sonar-scanner: command

hello, greetings.

i am trying to scan my code using sonarqube but i am getting error msg saying.

$ sonar-scanner -Dsonar.host.url=“${SONAR_HOST_URL}”

16bash: line 154: sonar-scanner: command not found

17ERROR: Job failed: exit status 1

i am using sonarqube shared command to scan my code but it still shows the same error.

kindly find my scan stage below.

variables:
SONAR_USER_HOME: “${CI_PROJECT_DIR}/.sonar” # Defines the location of the analysis task cache
GIT_DEPTH: “0” # Tells git to fetch all branches of the project, required by the analysis task

stages:

  • sonarqube-check

sonarqube-check:
stage: sonarqube-check
image:
name: sonarsource/sonar-scanner-cli:11
entrypoint: [“”] # Prevent default entrypoint
script:
- echo “Running SonarQube scan…”
- sonar-scanner -Dsonar.host.url=“${SONAR_HOST_URL}”
allow_failure: true
rules:
- if: $CI_PIPELINE_SOURCE == ‘merge_request_event’
- if: $CI_COMMIT_BRANCH == ‘master’
- if: $CI_COMMIT_BRANCH == ‘main’
- if: $CI_COMMIT_BRANCH == ‘develop’


i am using self hosted gitlab and my runner is set to execute shell job. how to address this issue

Hey there.

Take a look at this thread:

i tried installing gitlab cli and setting up jdk 17, but still the error persist.

backend@sonatype:~/project/pixupplaygameserver$ export $JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
-bash: export: `/usr/lib/jvm/java-17-openjdk-amd64=/usr/lib/jvm/java-17-openjdk-amd64’: not a valid identifier
backend@sonatype:~/project/pixupplaygameserver$ /var/opt/sonar-scanner-4.7.0.2747-linux/bin/sonar-scanner -Dsonar.projectKey=test -Dsonar.sources=. -Dsonar.host.url=http://10.20.0.12:9000 -Dsonar.token=sqp_51fef8fbfee1e5617750fc6bcceee9e59f028fc1
INFO: Scanner configuration file: /var/opt/sonar-scanner-4.7.0.2747-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14.1 Eclipse Adoptium (64-bit)
INFO: Linux 6.8.12-1-pve amd64
INFO: User cache: /home/backend/.sonar/cache
INFO: Scanner configuration file: /var/opt/sonar-scanner-4.7.0.2747-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 10.7.0.96327
INFO: Default locale: “en_US”, source code encoding: “US-ASCII” (analysis is platform dependent)
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.191s
INFO: Final Memory: 3M/56M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
at java.base/java.net.URLClassLoader.defineClass(Unknown Source)
at java.base/java.net.URLClassLoader$1.run(Unknown Source)
at java.base/java.net.URLClassLoader$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at org.sonarsource.scanner.api.internal.batch.DefaultBatchFactory.createBatch(DefaultBatchFactory.java:32)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
backend@sonatype:~/project/pixupplaygameserver$
Network error: Software caused connection abort

kindly note my gitlab is self hosted, how can i use a default gitlab runner.

also in above error my clt version is sonar-scanner-4.7.0.2747

tried this as well

backend@sonatype:~/project/pixupplaygameserver$ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
backend@sonatype:~/project/pixupplaygameserver$ /var/opt/sonar-scanner-4.7.0.2747-linux/bin/sonar-scanner -Dsonar.projectKey=test -Dsonar.sources=. -Dsonar.host.url=http://10.20.0.12:9000 -Dsonar.token=sqp_51fef8fbfee1e5617750fc6bcceee9e59f028fc1
INFO: Scanner configuration file: /var/opt/sonar-scanner-4.7.0.2747-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14.1 Eclipse Adoptium (64-bit)
INFO: Linux 6.8.12-1-pve amd64
INFO: User cache: /home/backend/.sonar/cache
INFO: Scanner configuration file: /var/opt/sonar-scanner-4.7.0.2747-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 10.7.0.96327
INFO: Default locale: “en_US”, source code encoding: “US-ASCII” (analysis is platform dependent)
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.212s
INFO: Final Memory: 3M/56M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
at java.base/java.net.URLClassLoader.defineClass(Unknown Source)
at java.base/java.net.URLClassLoader$1.run(Unknown Source)
at java.base/java.net.URLClassLoader$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at org.sonarsource.scanner.api.internal.batch.DefaultBatchFactory.createBatch(DefaultBatchFactory.java:32)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

Well, it’s not Java 17.

Your configuration of JAVA_HOME failed. You’ll want to change this to export JAVA_HOME (no $ identifier)

Hi i did that.