Openshift have a default maven Jenkins slave image, but too bad it is build on top of Java 8. And on this project which im currently working on, i need a custom Jenkins slave but with Java 11 and the ability to move images between Image Registry. Therefore i create a custom Dockerfile which contains Skopeo, Maven 3.6.3 and Java 11. Below is the detail Dockerfile which i created,
FROM openshift/jenkins-slave-base-centos7:v3.11
MAINTAINER Muhammad Edwin < edwin at redhat dot com >
ENV MAVEN_VERSION=3.6.3 \
PATH=$PATH:/opt/maven/bin
# install skopeo
RUN yum install skopeo -y && yum clean all
# install java
RUN curl -L --output /tmp/jdk.tar.gz https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz && \
tar zxf /tmp/jdk.tar.gz -C /usr/lib/jvm && \
rm /tmp/jdk.tar.gz && \
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.2/bin/java 20000 --family java-1.11-openjdk.x86_64 && \
update-alternatives --set java /usr/lib/jvm/jdk-11.0.2/bin/java
# Install Maven
RUN curl -L --output /tmp/apache-maven-bin.zip https://www-eu.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.zip && \
unzip -q /tmp/apache-maven-bin.zip -d /opt && \
ln -s /opt/apache-maven-${MAVEN_VERSION} /opt/maven && \
rm /tmp/apache-maven-bin.zip && \
mkdir -p $HOME/.m2
RUN chown -R 1001:0 $HOME && chmod -R g+rw $HOME
COPY run-jnlp-client /usr/local/bin/
USER 1001
Build by using this command,
docker build -t jenkins-slave-skopeo-jdk11-new -f skopeo-jdk11.dockerfile .
Pull the image to Openshift,
oc import-image docker.io/edwinkun/jenkins-slave-skopeo-jdk11-new --confirm
Register on Jenkins as a
And try on
node('maven') {
stage('Clone') {
sh "git config --global http.sslVerify false"
sh "git clone https://github.com/edwin/hello-world.git"
}
stage('Build') {
sh "mvn -v"
sh "mvn clean package -f hello-world/pom.xml"
}
}
Detail code can be seen on my github page, https://github.com/edwin/jenkins-slave-maven-jdk11-skopeo


Thank you Edwin, This saved me many days of work and was exactly what I need to help build a Quarkus using Jenkins pipelines on OpenShift 3.11. Many thanks again.