title: Jenkins Plugin Installation
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>This script works in script console but not inside post-initialization hook:</p>
  
  <pre><code>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()
  </code></pre>
  
  <blockquote>
    <p>I need a hook where system is started and uc.getPlugin(it) does not return null.</p>
  </blockquote>