0

Hi I am trying to get Sonarqube to work with Jenkins. I have jenkins running as a docker image and Sonarqube server running as two separate docker images on my host machine. I am using the SonarScanner plugin for Jenkins to scan my project. However, when I try to run the my pipeline the "/var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/test/bin/sonar-scanner" bash script returns the error could not find 'java' executable in JAVA_HOME or PATH.

This is strange because I can successfully echo JAVA_HOME within my Jenkins container. However, when I try to echo within the bash script, it returns nothing. I also tried manually setting the JAVA_HOME variable within the script but found the script cant execute java. I also followed the advice from this post:

Jenkins pipeline for react could not find 'java' executable in JAVA_HOME or PATH

but it still does not work. Here is my Jenkins pipeline script

pipeline {
    agent {
        docker {
            image 'node:6-alpine'
            args '-p 3000:3000'
        }
    }
    environment { 
        CI = 'true'
        scannerHome = tool 'test'
    }
    stages {
        stage('Build') {
            steps {
                sh 'npm install'
            }
        }
        stage('SonarQube analysis') {
            agent{ docker { image 'openjdk' }  }
            steps{
                withSonarQubeEnv('sonar') { 
                    sh "${scannerHome}/bin/sonar-scanner"
                }
            }
        }
        stage('Test') {
            steps {
                sh './jenkins/scripts/test.sh'
            }
        }
        stage('Deliver') { 
            steps {
                sh './jenkins/scripts/deliver.sh' 
                input message: 'Finished using the web site? (Click "Proceed" to continue)' 
                sh './jenkins/scripts/kill.sh' 
            }
        }
    }
}

mnsupreme
  • 125
  • 1
  • 6
  • Did you try to use the wrapper.java.command setting in wrapper.conf? – Jeroen Heier Nov 30 '19 at 17:34
  • I’m new to Jenkins and I’m not sure what the wrapper.conf file is. I tried looking it up but can’t seem to find a clear answer. – mnsupreme Dec 02 '19 at 04:55
  • Wrapper.conf is part of the SonarQube setup located in the conf folder. – Jeroen Heier Dec 02 '19 at 17:19
  • Well the build seems to be failing at the scanner side before it even reaches SonarQube server. In fact, I'm pretty sure the bash script that is failing is the script to start SonarScanner. So SonarScanner isn't even starting up – mnsupreme Dec 02 '19 at 21:36
  • @mnsupreme have u resolved this issue. Cause i m facing same issue too. Please help – Har devgun Jun 01 '20 at 12:40

0 Answers0