Best practices for Jenkins Controller in Dockerfile?

I’m in the process of setting up a Jenkins Controller - Worker configuration, and I want to make it easy to understand and maintain the setup. Thus, I’m trying to setup the Controller in a Docker container, have the plugins installed from a list in a text file, and have the configuration of everything handled through the Configuration as Code plugin.

So far, so good. I start with the jenkins/jenkins:lts-jdk11 image, bring my Configuration as Code files into the container and hook them up, and use jenkins-plugin-cli to install plugins. No prob.

However, I want to mount the jenkins_home directory to a directory on the machine running the container. This will allow the configuration to exist across container runs, and it is easier to target that one directory for backup. HOWEVER, because the plugins directory must be in jenkins_home, and because external volumes can’t be mounted during docker’s (or podman’s) build stage, I can’t mount an external jenkins_home directory and fill it with the plugins during the build phase.

Does anyone have experience with putting jenkins_home in an external volume/directory, and is willing to point me in the direction of best practices when putting together the Dockerfile?

Thanks!

thats not entirely true. I’d have to go dig and find out the specifics but you can shove plugins in /usr/share/jenkins/ref/plugins/ and that will copy over (without replacing) into $JENKINS_HOME/plugins

So, you could update your entrypoint to delete $JENKINS_HOME/plugins every startup

I use helm which has a flag to delete the contents of the directory, but my docker image has all the plugins in the ref directory

(ignore the env CASC_HOME as helm overrides it, and i was just lazy to remove that line from the docker file)

1 Like