Note: This is part 2 of the Jenkins docker series. Click here for part 1.
You want to spawn a Jenkins Docker container that already has some default plugins of your choice pre-installed so that you don't have to install those manually.
TLDR: Bitbucket code here.
Jenkins provides a shell script that is meant exactly for that use-case. It's called install-plugins.sh and it is already part of the jenkins/jenkins:lts image.
So the easiest way is to utilize that script by feeding it a text file that has all required default plugins listed up. This will be the approach taken in this post.
We will also make use of the REF environmental variable that is set up by default and points to /usr/share/jenkins/ref.
Continuing with the Dockerfile from Part 1 of this tutorial series, we will extend it by
- chmoding $REF (since we changed the jenkins user ID of the default image),
- copying a plugins.txt file from the build environment to $REF/init.groovy.d (which is also already set up by Jenkins image),
- executing the install-plugins.sh script with the plugins.txt as input.
These changes lead to the following Dockerfile: