Skip to content

Instantly share code, notes, and snippets.

@sergeyhush
Created December 23, 2016 07:53
Show Gist options
  • Save sergeyhush/77e95c7fe6cf546eef99d4d91e8918c0 to your computer and use it in GitHub Desktop.
Save sergeyhush/77e95c7fe6cf546eef99d4d91e8918c0 to your computer and use it in GitHub Desktop.
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