Skip to content

Instantly share code, notes, and snippets.

@rsandell
Created August 25, 2016 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsandell/60e046f46d78edcd7ad62cf7a5e5c760 to your computer and use it in GitHub Desktop.
Save rsandell/60e046f46d78edcd7ad62cf7a5e5c760 to your computer and use it in GitHub Desktop.
A script that installs all missing plugins from a list produced by a Jenkins support bundle
class Consts {
static final String jar = "/home/rsandell/jenkins/cje2/war/WEB-INF/jenkins-cli.jar"
static final String java = "/home/rsandell/java/jdk1.8.0_73/bin/java"
static final String url = "http://bobby.local:8081"
static final String cli = "${java} -jar ${jar} -s ${url}"
}
final String remotePluginsFile = "/home/rsandell/jenkins/active.txt"
def getInstalledPlugins() {
"${Consts.cli} list-plugins".execute().text.readLines().collect { String line ->
def m = line =~ /([\w\-_]+)\s+[\w\s]+(\d[\d\w\-.]+)/
if (m.find()) {
return [name: m.group(1), version: m.group(2)]
}
}
}
void install(String name) {
print "Installing ${name}..."
def process = "${Consts.cli} install-plugin ${name} -deploy".execute()
println(process.waitFor())
println(" ${process.text}")
if (process.exitValue() != 0) {
println(" ${process.err.text}")
}
}
List<Map> installed = getInstalledPlugins()
println "Installed:\n${installed}"
List<Map> remote = new File(remotePluginsFile).readLines().collect {String line ->
String[] split = line.split(":")
return [name: split[0], version: split[1]]
}
println("Remote:\n${remote}")
remote.each {def pl ->
if (!installed.find {it?.name == pl?.name}) {
install(pl.name)
}
}
installed = getInstalledPlugins()
remote.each {def pl ->
def plInstalled = installed.find { it?.name == pl?.name }
if (!plInstalled) {
println "Missing ${pl.name}"
} else if (pl.version != plInstalled.version){
println "Version ${pl.name}.${pl.version} != ${plInstalled.version}"
} else {
println "OK ${pl.name}"
}
}
@rsandell
Copy link
Author

Much QnD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment