javashelljenkinsjenkins-scriptler

Java not recognized when running a shell script from Jenkins


I am trying to run/invoke a java program on a Jenkins slave using Jenkins. I am getting the error Javac is not recognized. But when i invoke the same program from the jenkins slave host directly, the java program perfectly works fine. I tried setting the java home by export $java_home on the shell script itself but it doesn't seem to do any help. Checked the versions of java and all looked okay. Any thoughts/ideas??


Solution

  • Effective value PATH variable in that script does not have java. There are many ways to solve it.

    Option 1

    User absolute path to your java. You already have JAVA_HOME defined. So refer to java as $JAVA_HOME/bin/java ...

    Option 2

    Variant of above. Add $JAVA_HOME/bin to PATH. Like below

      export PATH=$JAVA_HOME/bin:$PATH
    

    Option 3

    Further variation on above. Allow Jenkins to install JDK and set environment variable pointing to installation. Use this environment variable in your script.