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

Issue

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/jenkins5934784799261667748.sh
+ 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/jenkins5934784799261667748.sh: line 4: /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/java: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Environment

Resolution

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/jdk.sh
[jdk9] $ tar xzf /home/jenkins/agent/tools/hudson.model.JDK/jdk9/jdk.sh
[tool-install-in-podtemplate] $ /bin/sh -xe /tmp/jenkins2206147577201821280.sh
+ 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/ld-linux-x86-64.so.2 (0x7fd770717000)
	libz.so.1 => /lib/libz.so.1 (0x7fd7706fd000)
	libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fd770717000)
	libjli.so => /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/../lib/jli/libjli.so (0x7fd7704ee000)
	libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fd770717000)
	libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fd770717000)
Error relocating /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/../lib/jli/libjli.so: __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

    Note: 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.

    jdk9

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

  3. install JGit,

    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,

    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
        linux-vdso.so.1 =>  (0x00007ffe2a6cf000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f4452312000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f44520f6000)
        libjli.so => /home/jenkins/agent/tools/hudson.model.JDK/jdk9/bin/../lib/jli/libjli.so (0x00007f4451ee7000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f4451ce3000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f4451916000)
        /lib64/ld-linux-x86-64.so.2 (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 https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip 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] ----------------------< com.mycompany.app:my-app >----------------------
    [INFO] Building my-app 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
    [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (3.9 kB at 4.1 kB/s)
    [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom
    [INFO] Downloaded from central:
    ...
    

Reference

Have more questions?

0 Comments

Please sign in to leave a comment.