chanukhya bachina
chanukhya bachina

Reputation: 181

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??

Upvotes: 0

Views: 3855

Answers (2)

vinodhraj
vinodhraj

Reputation: 217

I specified the absolute value of Java path in Environment variables in Node Properties like below

JAVA_HOME

C:\Program Files\Java\jdk-17

And it worked

Upvotes: 0

Jayan
Jayan

Reputation: 18459

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.

Upvotes: 0

Related Questions