Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Collection of useful methods for Jenkins to be used in init.groovy.d
import jenkins.model.Jenkins
class InitGroovyD {
/**
* Install plugins.
*
* @param plugins Plugins to be installed
*/
static installPlugins(String... plugins) {
def updateCenter = Jenkins.instance.updateCenter
updateCenter.updateAllSites()
def pluginsNotInstalled = { !Jenkins.instance.manager.getPlugin(it) }
def installed = false
plugins.findAll { pluginsNotInstalled }.each {
def plugin = updateCenter.getPlugin(it)
if (plugin) {
plugin.deploy()
installed = true
}
}
if (installed) {
Jenkins.instance.with {
save()
doSafeRestart()
}
}
}
}
InitGroovyD.installPlugins('git')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment