2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Jenkins Plugin Management in Groovy

Posted at

Originally posted in http://aespinosa.github.io/blog/2014-10-17-jenkins-plugin-management-in-groovy.html

In conjuction with Habit#4 (Tend your Plugin Garden) in [1] . I want to just
have the plugins I want on my Jenkins deployment. For my use case, I don't want
to have vanilla deployed plugins like the CVS plugin. Here is a way to disable
all plugins at the start.

plugins = Jenkins.instance.pluginManager.plugins
plugins.each {
  it.disable()
}

Plugin Installation

Instead of having your outer config management download the .hpi/ .jpi and
wrangle with dependencies yourself, you can take advantage of Jenkin's builtin
Java calls to do exactly the same thing. With this, you can install a plugin
from the script console.

Jenkins.instance.updateCenter.getPlugin("git").deploy()

Enable a plugin's dependencies

In the previous section, some of the dependencies will be disabled even though
they got updated to the version required by the Git plugin because of the first
step we did to disable all plugins. Here, we get all the plugin's dependencies,
and sub dependencies to enable all of them.

git = pm.getPlugin("git")

def deployPlugin(plugin) {
  if (! plugin.isEnabled() ) {
    plugin.enable()
  }
  plugin.getDependencies().each { 
    deployPlugin(pm.getPlugin(it.shortName)) 
  }
}

deployPlugin(git)

[1] http://www.slideshare.net/andrewbayer/seven-habits-of-highly-effective-jenkins-users-2014-edition

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?