I’m trying to create a Docker cloud agent and I want to launch the container with “Launch attached” method.
In that section, it has suggested to use “jenkins/agent” image as a base image. But I don’t want to use “jenkins/agent” as base image.
But I didn’t find any documentation related to what other steps I need to follow, if I go with images other than jenkins/xyz.
Like, If I go with using “maven:3.9.7-eclipse-temurin-8”,
Should I create a user called “jenkins” in that image?
And should I deploy “agent.jar” executable in that image?
Where do I get “agent.jar” from?
Where should I deploy that?
All of this is because, when I already have an image which has both required Java and Maven in one place, I don’t want to use “jenkins/XYZ” image and install maven there with apt-get commands.
And yes, I’ve also tried searching for “jenkins/agent:maven” but unfortunately, there is only “jenkins/agent:jdk” version but not maven version.
Why don’t you want to use that base image as a known starting point? You’re much more likely to succeed with your agent work if you start with a base image that is known to work.
It is much easier for Jenkins plugin maintainers to describe a known starting point (the jenkins/agent base image) than to describe the steps that are required to replicate the known starting point in an unknown container image.
Extending the known starting point is more likely to allow Jenkins to connect that container as an agent. Creating your own container without using the known starting point is much less likely to connect as an agent. A very good example of that is included in your later text where you say:
The maven:3.9.7-eclipse-temurin-8 container image includes Java 8 as delivered by the Eclipse Temurin project and Apache Maven 3.9.7. That container won’t run as an agent without significant additions.
Jenkins controllers stopped supporting Java 8 two years ago for controller and for running agents. In order to use that container image as a Jenkins agent, you’ll need to extend the container image to include a Java version that Jenkins supports (Java 17 or Java 21 preferred) and you’ll need to install the agent jar file, and you’ll need to adapt the start process of that container so that it can be launched by Jenkins as a container. The maven:3.9.7-eclipse-temurin-8 container image default start process is designed to allow users to run Apache Maven from a command line.
The Jenkins infra team defines the container images used for ci.jenkins.io jobs. I believe that they start with the jenkins/agent container images and then add the Java versions that are needed and the Maven versions that are needed.
I tried using “FROM jenkins/agent:jdk8”. But as you told it seems Jenkins doesn’t support Java 8 agents anymore. I’m getting below error.
java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
But my project requires Java 8.
What are my options now to use “jenkins/agent” and still get Java 8 working?
Extend the Jenkins agent definition by installing Java 8 in a separate directory. Define a Jenkins tool for Java 8 and have the job definition reference that tool. Refer a previous answer for more details and refer to this video by Darin Pope
FROM jenkins/agent:jdk17
USER root
WORKDIR /opt
RUN apt update
RUN apt install wget tar
RUN wget https://download.java.net/openjdk/jdk8u44/ri/openjdk-8u44-linux-x64.tar.gz
RUN tar -zxvf openjdk-8u44-linux-x64.tar.gz
# Attention !!!! you should not set below 2 ENV variables as it will make Java 8 as default on container level itself and you will get previously mentioned "Compiled java version" related Exception.
# ENV JAVA_HOME=/opt/java-se-8u44-ri
# ENV PATH=$JAVA_HOME/bin:$PATH
RUN wget https://dlcdn.apache.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz
RUN tar -zxvf apache-maven-3.9.8-bin.tar.gz
ENV MAVEN_HOME=/opt/apache-maven-3.9.8
ENV M2_HOME=/opt/apache-maven-3.9.8
ENV PATH=$MAVEN_HOME/bin:$PATH