I have written a Jenkins Groovy Script for installing Jenkins plugin at startup. Groovy scripts are named after the Hook that is used to invoke my scripts. E.g. init.groovy is triggered inside the init-Hook. This Hook is triggered in post-initialization.
During initialization I have no access to the UpdateCenter and cannot install the plugins. What other Jenkins Hooks can I use? In my opinion I need a post-startup Hook.
This script works in script console but not inside post-initialization hook:
import jenkins.model.*
def pluginParameter="gitlab-plugin hipchat swarm"
def plugins = pluginParameter.split()
println(plugins)
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
def installed = false
plugins.each {
if (!pm.getPlugin(it)) {
def plugin = uc.getPlugin(it)
if (plugin) {
println("Installing " + it)
plugin.deploy()
installed = true
}
}
}
instance.save()
if (installed)
instance.doSafeRestart()
I need a hook where system is started and uc.getPlugin(it) does not return null.
Solved this by asking the jenkins-irc channel. I needed to initialize the UpdateCenter's list of update sites. The result can be found here: blacklabelops/jenkins
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With