How to Duplicate a Jenkins server for local plugin integration debugging

Suppose you need to quickly test to see if specific versions of Jenkins plugins aren’t working well with each other. Suppose also that you cannot debug these plugins in a production environment (or other sensitive reasons) and you need help to replicate the environment such that you can see if plugins can coexist.

Here’s an approach that I found by piecing together a few other articles together (links below):

  1. Get list of plugins
  2. Configure an easily resettable, local Jenkins server
  3. Prepopulate and launch

Get List of Plugins

Under Jenkins Home (you may need to ask for permissions) go to the script console

[picture of script console]

Type in the following to get a list of plugins.

Jenkins.instance.pluginManager.plugins.sort { it.getDisplayName() }.each{
  plugin -> 
    println ("${plugin.getDisplayName()} (${plugin.getShortName()}):${plugin.getVersion()}")
}

You should get an output that looks similar to

some-plugin:1.0.0
cool-plugin:1.0.3
company-specific-plugin:1.3.0 company.com/artifacts/plugins/company-specific-plugin-1.3.0.hpi

Save this to a local file: ./plugins.txt. Note that if you have specific URLs that you know that your start-up or company uses for local artifacts and plugins, you can place it afterwards in the same line.

Configure Local Jenkins Server

Write up a Dockerfile to get the latest Jenkins (or find the specific Docker image). It will also grab that list of plugins, and copy it in for installation.

FROM jenkins/jenkins:lts
COPY plugins.txt ./plugins.txt
RUN /usr/local/bin/install-plugins.sh < plugins.txt

The script referenced in that Dockerfile, (./install_jenkins.sh) can be found here.

After building the image (you can call it whatever you want; I’m calling it jenkins) you can setup a script that will restart it (and display the initial admin password). This may be called ./restart_jenkins.sh and invoked as such.

// enter ./restart_jenkins.sh

To build the image, simply run this command.

> docker build -t jenkins .

Launch

Point your browser to localhost:8787.

Enjoy.

Credits