In Building a Custom Jenkins Docker Image - Part 1 we disabled the Jenkins install wizard and installed the default plugins. In part 2, I want to focus on ensuring the build tools are installed. The target end state of our build infrastructure must include the installation and configuration of:
This means that the official Jenkins image is based on the openjdk:8-jdk image (Java 8 JDK is installed) and that the Git client is installed. There is nothing to suggest that Maven is installed and we can verify this by creating a new bash session in the container and listing the installed packages.
To install maven we use the Docker RUN statement in the Jenkins/Dockerfile to invoke apt-get install. This requires us first to become the root user and subsequently to resume as the jenkins user.
I can now build a new Docker image:
Note that I have changed the version tag.
As this is a personal exercise in learning about Kubernetes and Docker, I attempted to perform a rolling update of the deployment but this required using hostPath persistent volumes. Minikube does not yet support running containers with non root users and hostPath volumes (which are provisioned by root user). See this guthub pull request for more information.
Then recreate the pod.
It’s possible to verify the update by describing the pod:
To validate that maven is now installed within the container I can create a new bash session in the container and run apt list –installed.
You can also go ahead and create a build job via the Jenkins UI for one of your Java maven projects (i used this one). A couple of things that I skipped over:
I used the HTTPS protocol for the git repository to avoid having to add github to the known_hosts file.
I created the job manually rather than scripting the job creation.
I need to create equivalent jenkins slave images with tooling installed.
Those are a few follow up tasks I’ll get to over the next couple of weeks.