Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Plugin Installation

Tags:

jenkins

groovy

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.

like image 342
blacklabelops Avatar asked Jul 16 '15 14:07

blacklabelops


1 Answers

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

like image 157
blacklabelops Avatar answered Sep 20 '22 15:09

blacklabelops