skip to Main Content

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

  1. That the path is correct /opt/java/openjdk
    https://hub.docker.com/layers/gradle/library/gradle/jdk8-jammy/images/sha256-8fe6aa6c268162cbb00e0873e94e8c8a49aea1d3bdf7a3c7499751f227f5dfc6?context=explore

  2. 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
  1. It builds perfectly fine locally when do I skaffold build with local profile. But fails in Jenkins.
  2. 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


  1. 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.

    Login or Signup to reply.
  2. 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:

    13:34:46  Step 9/23 : RUN ls -la /opt/java/openjdk/bin/java
    13:34:46   ---> Running in d7a82558e4b2
    13:34:47  -rwxr-xr-x 1 root root 12768 Apr 19 21:38 /opt/java/openjdk/bin/java
    

    but when I test for executable perms I get:

    13:24:57  Step 10/22 : RUN test -x $JAVA_HOME/bin/java
    13:24:57   ---> Running in 20dd8d832464
    13:24:57  The command '/bin/sh -c test -x $JAVA_HOME/bin/java' returned a non-zero code: 1
    

    It looks like commands are being run as root as well:

    13:19:06  Step 10/21 : RUN id -u -n
    13:19:06   ---> Running in 1ea36050bc88
    13:19:06  root
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search