| When looking at the JavaDoc for Jenkins' UpdateCetner
getPlugin() is referencing the hudson.util.VersionNumber. However, it is not listed in the JavDocs, the CLI docs return a 404, and while its listed here:
Its not actually in the Jenkins code base:
I found this when attempting to setup Jenkins using Groovy to go from zero-to-hero and it failed to run on a fresh install, but worked after I had initially setup by hand.
#!groovy
import jenkins.model.Jenkins
import hudson.util.VersionNumber
// Create a reference to the PluginManager Class.
pm = Jenkins.instance.pluginManager
// Create a reference to the UpdateCenter Class.
uc = Jenkins.instance.updateCenter// Disable all the plugins on the system first.
pm.plugins.each { plugin ->
plugin.disable()
}
// Used to make sure that the plugins actually installed, and whether or not
// they actually deployed.
deployed = false/**
* activatePlugins is a recursive function that installs and enables the plugins
* and their dependencies.
* However, these don't actually do any version pinning, and picks the latest
* versions of the plugins.
*
* @param plugin [Object]
*
* @return nil
*/
def activatePlugin(plugin) {
if (!plugin.isEnabled()) {
plugin.enable()
deployed = true
} plugin.getDependencies().each {
activatePlugin(pm.getPlugin(it.shortName))
}
}[
'ant':'1.9', // v1.9
'build-timeout':'1.19', // v1.19
'credentials':'2.1.18', // v2.1.18
'email-ext':'2.63', // v2.63
'github-branch-source':'2.4.1', // v2.4.1
'gradle':'1.29', // v1.29
'jobConfigHistory':'2.19', // v2.19
'ldap':'1.20', // v1.20
'matrix-auth':'2.3', // v2.3
'antisamy-markup-formatter': '1.5', // v1.5
'pam-auth':'1.4', // v1.4
'workflow-aggregator':'2.6', // v2.6
'pipeline-github-lib':'1.0', // v1.0
'ssh-slaves':'1.29.1', // v1.29.1
'subversion':'2.12.1', // v2.12.1
'timestamper':'1.8.10', // v1.8.10
'ws-cleanup':'0.37' // v0.37
].each { plugin, version ->
if (! pm.getPlugin(plugin)) {
VersionNumber versionNumber = new VersionNumber(version)
deployment = uc.getPlugin(plugin, versionNumber).deploy(true)
deployment.get()
}
activatePlugin(pm.getPlugin(plugin))
}// Do a simple verification that the plugins did deploy, then restart Jankins
if (deployed) {
Jenkins.instance.restart()
}
|