Not found error when trying to install JDK and Maven tool to a Kubernetes pod agent

Article ID:360038543831
2 minute readKnowledge base


When attempting to use Global Tool Configuration to install both JDK and Maven to a Kubernetes pod agent, Maven cannot find the installed JDK with error "not found". E.g. Freestyle Project using an Execute shell of,

j=$(which java)
${j} -version

Results in output,

[tool-install-in-podtemplate] $ /bin/sh -xe /tmp/
+ which java
+ j=/home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java
+ /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java -version
/tmp/ line 4: /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE


The issue is that the default pod agent (the jenkins/inbound-agent:latest image) is based on Alpine Linux. Amongst other differences, Alpine uses musl libc. And the error "not found" is not that Maven cannot find the JDK, it’s that a symbol is expected and "not found" from the musl libc. Below is a Freestyle Project with an Execute shell containing the following commands,

j=$(which java)
ldd ${j}
${j} -version

The resulting output,

Building remotely on default-java-d8wr3 in workspace /home/jenkins/agent/workspace/tool-install-in-podtemplate
Installing /home/jenkins/agent/tools/hudson.model.JDK/jdk9/
[jdk9] $ tar xzf /home/jenkins/agent/tools/hudson.model.JDK/jdk9/
[tool-install-in-podtemplate] $ /bin/sh -xe /tmp/
+ which java
+ j=/home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java
+ ldd /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java
	/lib64/ (0x7fd770717000) => /lib/ (0x7fd7706fd000) => /lib64/ (0x7fd770717000) => /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/../lib/jli/ (0x7fd7704ee000) => /lib64/ (0x7fd770717000) => /lib64/ (0x7fd770717000)
Error relocating /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/../lib/jli/ __rawmemchr: symbol not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

The JDK tool was built using the glibc (GNU Libc) and therefore the resolution is to use a glibc-based image. Debian-based and Redhat-based images will have glibc as it’s standard C library.

Therefore, follow these steps to install both JDK and Maven to a Kubernetes pod agent.

  1. Go to Manage Jenkins and Kubernetes Pod Templates and create a pod template selecting an image using glibc. Example: openjdk:latest,

    pod template definition
    Defining the 'jnlp' container, i.e. replacing the default pod agent, allows us to use a Freestyle Project to build using Pod agent templates.
  2. Go to Manage Jenkins and Global Tool Configuration and install Java, e.g.

    don’t forget to check 'I agree to the Java SE Development Kit License Agreement'.

  3. install JGit,

    Our chosen image doesn’t have Git pre-installed. We’ll need to install JGit to allow us to fetch our source.

  4. install Maven,

  5. Go to your Freestyle Job configuration and configure the source, e.g. Git,

    git source
  6. check off 'Restrict where this project can be run' and fill it with the pod template name you selected, e.g. we used 'openjdk-latest'

  7. and configure Build steps, e.g. Execute shell and Invoke top-level Maven targets,

    build steps

    The resulting build will have output (truncated),

     ++ which java
     + j=/home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java
     + ldd /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java =>  (0x00007ffe2a6cf000) => /lib64/ (0x00007f4452312000) => /lib64/ (0x00007f44520f6000) => /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/../lib/jli/ (0x00007f4451ee7000) => /lib64/ (0x00007f4451ce3000) => /lib64/ (0x00007f4451916000)
         /lib64/ (0x00007f4452528000)
     + /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java -version
     java version "9.0.4"
     Java(TM) SE Runtime Environment (build 9.0.4+11)
     Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
     Unpacking to /home/jenkins/agent/tools/hudson.tasks.Maven_MavenInstallation/maven3 on openjdk-latest-ql9j8
     [175451] $ /home/jenkins/agent/tools/hudson.tasks.Maven_MavenInstallation/maven3/bin/mvn -DskipTests=true -B clean package
     [INFO] Scanning for projects...
     [INFO] ----------------------< >----------------------
     [INFO] Building my-app 1.0-SNAPSHOT
     [INFO] --------------------------------[ jar ]---------------------------------
     [INFO] Downloading from central:
     [INFO] Downloaded from central: (3.9 kB at 4.1 kB/s)
     [INFO] Downloading from central:
     [INFO] Downloaded from central: