While building the image in Jenkins gradle build fails with the error
ERROR: JAVA_HOME is set to an invalid directory: /opt/java/openjdk
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Following is the part of the Dockerfile. The RUN gradle build is what fails.
FROM gradle:7.4.2-jdk8 as builder
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle build --no-daemon
What I have checked
-
That the path is correct /opt/java/openjdk
https://hub.docker.com/layers/gradle/library/gradle/jdk8-jammy/images/sha256-8fe6aa6c268162cbb00e0873e94e8c8a49aea1d3bdf7a3c7499751f227f5dfc6?context=explore -
What fails is the following gradle check : https://github.com/marklogic-community/ml-gradle/blob/9816f8756e8a6c656cb2371a4d9f85405e39e6d8/gradlew#L73
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
- It builds perfectly fine locally when do I skaffold build with local profile. But fails in Jenkins.
- So the path exists so I am not sure why the -x check fails and only in Jenkins. It is executable by the user and group -> gradle:1000:1000 – that comes with the image : gradle:7.4.2-jdk8
I would appreciate any insight to this issue. Thank you.
2
Answers
same issue with TeamCity agent. It runs docker-in-docker.
In container (DockerInDocker)
test -x $JAVA_HOME/bin/java
returns 1.In agent
test -x $JAVA_HOME/bin/java
returns 0.0777 mode, root owner as well.
Also seeing the same issue in Jenkins running on k8s. Using
eclipse-temurin:11.0.15_10-jdk
as the base image. Checking the Java executable before gradlew is called give me:but when I test for executable perms I get:
It looks like commands are being run as root as well:
What makes it weirder is that I’m able to manually create the same Jenkins pod used for builds, exec in and clone the repo and build the Docker image successfully with no issues.