Skip to content

Instantly share code, notes, and snippets.

@childnode
Last active January 29, 2018 14:07
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 childnode/cfe3ce65e0fd8d2ced7302cabc721320 to your computer and use it in GitHub Desktop.
Save childnode/cfe3ce65e0fd8d2ced7302cabc721320 to your computer and use it in GitHub Desktop.
Jenkins plugins.txt
FROM jenkins/jenkins:${jenkinsVersion}
## note base : https://github.com/jenkinsci/docker/blob/master/Dockerfile
## Manual install Plugins
COPY myPlugin.hpi /usr/share/jenkins/ref/plugins/myPlugin.jpi
RUN unzip -qqt "/usr/share/jenkins/ref/plugins/myPlugin.jpi"
FROM jenkins/jenkins:${jenkinsVersion}
## note base : https://github.com/jenkinsci/docker/blob/master/Dockerfile
## Install Plugins via plugins.txt definition from online repository
COPY plugins.txt /plugins.txt
RUN /usr/local/bin/install-plugins.sh $(cat /plugins.txt | grep -v "^#")
/* using the https://jenkins.io/doc/book/managing/script-console/
* NOTE: result will include any plugin actually installed
* it doesn't care about if this is a "intended" installed
* plugin or if it's just a technical "requirement" included
* by another plugin
*/
// http://javadoc.jenkins.io/hudson/PluginWrapper.html
Jenkins.instance.pluginManager.plugins
.sort()
.stream()
.each{
plugin ->
println ("${plugin.getShortName()}:${plugin.getVersion()}")
}
/* using the https://jenkins.io/doc/book/managing/script-console/
* NOTE: THIS LIST only includes independent plugins,
* all other plugins are implied in dependencies and
* haven't to be installed "manually" by plugins.txt
* BUT: if dependencies are updated, this plugins.txt
* will not include the instruction for the actual
* installed plugin version but might be "downgraded"
* on reinstall (due to the latest required dependency)
* it NEITHER lists dependencies of dependencies!!
*/
// http://javadoc.jenkins.io/hudson/PluginWrapper.html
Jenkins.instance.pluginManager.plugins
.sort()
.stream()
.filter{ !it.hasDependants() }
.each{
plugin ->
println ("## ${plugin.getDisplayName()}")
println ("# https://plugins.jenkins.io/${plugin.getShortName()}")
println ("# ${plugin.getUrl()}")
println ("# implies: ${plugin.dependencies}")
println ("${plugin.getShortName()}:${plugin.getVersion()}\n")
}
/* using the https://jenkins.io/doc/book/managing/script-console/ */
Jenkins.instance.pluginManager.plugins
.sort()
.stream()
.filter{ !it.hasDependants() }
.each{
plugin ->
println ("## ${plugin.getDisplayName()}")
println ("# https://plugins.jenkins.io/${plugin.getShortName()}")
println ("# ${plugin.getUrl()}")
println "# transitive dependencies:"
plugin.dependencies.stream()
.map{dep -> Jenkins.instance.pluginManager.plugins.stream().filter{ it.getShortName() == dep.shortName }.findFirst().get() }
.each{ println "## ${it.getShortName()}:${it.getVersion()} ${it.dependencies}" }
println ("${plugin.getShortName()}:${plugin.getVersion()}\n")
plugin.dependencies.each {
dep ->
Jenkins.instance.pluginManager.plugins
.stream()
.filter{
it.getShortName() == dep.shortName && it.getVersion() > dep.version
}
.each{
println ("# ${plugin.getShortName()} dependent on ${it.shortName} for version ${dep.version} but installed in ${it.version}")
println ("${it.shortName}:${it.version}\n")
}
}
}
def getDependencies(plugin, known) {
def allDeps = []
if (known.contains(plugin)) { return allDeps; }
// println "# transitive dependencies for ${plugin}: ${plugin.dependencies}"
plugin.dependencies.stream()
.map{dep ->
Jenkins.instance.pluginManager.plugins.stream().filter{ it.getShortName() == dep.shortName }
/*
.peek{ allDeps.contains(it) ?: print("\n## ${dep}") }
.peek{ (dep.version < it.version && !allDeps.contains(it)) ? print(" (depended, but seen installed version ${it.version})\n${it.shortName}:${it.version}") : print("\n") }
*/
.peek{ if (dep.version < it.version && !known.contains(it)) {
// println ("# ${plugin.getShortName()} dependent on ${it.shortName} for version ${dep.version} but installed in ${it.version}")
println("${it.shortName}:${it.version}") }
}
.peek{ allDeps.add(it) }
.findFirst().get()
}
.each{ allDeps.addAll(getDependencies(it, known)) }
known.addAll(allDeps);
return allDeps; //.sort().stream().distinct().toArray();
}
/* using the https://jenkins.io/doc/book/managing/script-console/ */
allProcessedDeps = [ ]
Jenkins.instance.pluginManager.plugins
.sort()
.stream()
.filter{ !it.hasDependants() }
.each{
plugin ->
println ("## ${plugin.getDisplayName()}")
println ("# https://plugins.jenkins.io/${plugin.getShortName()}")
println ("# ${plugin.getUrl()}")
installedDependencies = getDependencies(plugin, allProcessedDeps)
//installedDependencies.each{ println "## ${it.shortName}:${it.version}" }
println ("${plugin.getShortName()}:${plugin.getVersion()}\n")
}
/* using the https://jenkins.io/doc/book/managing/script-console/ */
// http://javadoc.jenkins.io/hudson/PluginManager.html
// http://javadoc.jenkins.io/hudson/PluginWrapper.html
def printDependencies(depList, prefix = " ") {
depList.stream()
.peek{ println "|${prefix}|- ${it}" }
.map{dep -> Jenkins.instance.pluginManager.plugins.stream().filter{ it.getShortName() == dep.shortName }.findFirst().get() }
.each{ printDependencies(it.dependencies, prefix + "| ") }
}
Jenkins.instance.pluginManager.plugins
.sort()
.stream()
.filter{ !it.hasDependants() }
.each{
plugin ->
println ("|- ${plugin.getShortName()}:${plugin.getVersion()}")
printDependencies(plugin.dependencies)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment