Java not found in Jenkins job when running SonarQube Scanner

Viewed 3348

I have Jenkins and Sonar running in separate Docker containers. I want to run the Sonar analysis in a Jenkins job, so I installed the "SonarQube Scanner for Jenkins" plugin.

This is the job configuration: Build configuration in Jenkins

I'm getting this error when I run the build:

[run-sonar] $ /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/my_SonarScanner/bin/sonar-scanner -e -Dsonar.host.url=http://localhost:9000 -Dsonar.projectBaseDir=/var/jenkins_home/workspace/run-sonar
/var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/my_SonarScanner/bin/sonar-scanner: exec: line 73: /var/jenkins_home/tools/hudson.model.JDK/java8/bin/java: not found
ERROR: SonarQube scanner exited with non-zero code: 127
Finished: FAILURE

Java8 was installed by Jenkins when the job ran for the first time. If I log in to the Jenkins container and cd to that folder, it exists.

1 Answers

I was able to fix it by manually changing the path where SonarQube is trying to execute Java.

In /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/my_SonarScanner/bin/sonar-scanner, I removed these lines:

if [ -n "$JAVA_HOME" ]                                         
then                                          
  java_cmd="$JAVA_HOME/bin/java"                                                 
else                         
  java_cmd="$(which java)"                             
fi

And fixed the variable to point to the $JAVA_HOME configured on that container.

java_cmd=/usr/lib/jvm/java-1.8-openjdk/bin/java
Related