Reputation: 191789
I am using Jenkins to build an android project on a mac stadium VM.
When I VNC into the VM, I can build the project just fine. Java is installed at /usr/bin/java
, and my $PATH
includes /usr/bin
.
When I run the same commands from the Jenkins job, it fails with
ERROR: JAVA_HOME is set to an invalid directory: /var/lib/jenkins/jdk1.8.0_25
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
/var/lib/jenkins/jdk...
does not exist on the VM. I have also tried updating the build job to include export JAVA_HOME=/usr/bin
, but then I get a different error:
Error: Failed to run "java -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: /usr/bin
All of the other steps seem to work so I can tell that the code is being downloaded to the workspace and everything else is installed properly, and as I said I can build android on the VM from the command line directly.
What can I do to get Jenkins to build on the VM?
Upvotes: 1
Views: 4834
Reputation: 2705
The best way to set the JAVA_HOME on a mac is to use java_home
after downloading and installing the required JDK from oracle:
export JAVA_HOME=`/usr/libexec/java_home`
If you want Jenkins to use an older version of the JDK ensure use the -v flag:
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
To preview the location just type the java_home command into a Terminal:
$ /usr/libexec/java_home -v 1.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home
Upvotes: 7