Jenkins : Dump your plugins
About this
This post is mostly a foreword to the next one about jenkins dev environments but since it can be useful on its own I left it aside. This is a quick post, no fancyness here
Sometimes you need the list of your plugins installed: for backup, to recreate a server, to debug an upgrade gone wrong or anything else. This post explains how to automate this, with jenkins itself
How
Using a groovy script as a build step with the Groovy plugin, you can simply dump your installed plugins to a file :
plugins = []
excluded = [ ~/^ease.*/, ~/^codex.*/ ]
hudson.model.Hudson.instance.pluginManager.plugins.each { it
matched = false
plugin = "${it.getShortName()}:${it.getVersion()}"
excluded.each { e ->
if (plugin =~ e) {
println "skipping ${plugin}"
matched = true
}
}
if (matched == false) { plugins << plugin}
}
hudson.FilePath workspace = hudson.model.Executor.currentExecutor().getCurrentWorkspace()
def dump = new File(workspace.toString()+"/docker/master/plugins.txt")
dump.withWriter { out ->
plugins.sort().each { out.println it }
}
Here the path is docker/master/plugins.txt
as a reference to our dev setup, but you can put it anywhere of course. The excluded
variable is an array of regex to exclude any plugins you don’t want to see listed (here to handle a difference between prod and dev)