Created
December 23, 2016 07:53
-
-
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
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
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