Created
August 25, 2016 10:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Much QnD