Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Someone posted this to a forum... as an attachment...
import jenkins.model.*
import java.util.logging.Logger
def logger = Logger.getLogger("02_installPlugins.groovy")
def installed = false
def initialized = false
def fileSeperator=File.separator;
println("Plugins Count Before Installation: "+Jenkins.instance.pluginManager.plugins.size())
def filepath="/home/lvadmin/.jenkins/init.groovy.d"+fileSeperator+"pluginslist.cfg";
println "pluginslist.cfg FilePath : $filepath"
def pluginslist = []
def instance = Jenkins.getInstance()
def pm = instance.getPluginManager()
def uc = instance.getUpdateCenter()
if(new File( filepath).exists()){
new File( filepath ).eachLine { line ->
pluginslist << line
}"Pluginslist count: "+pluginslist.size())"Pluginslist to be installed: "+pluginslist)
pluginslist.each { "-------------->>>>> Installing Plugin "+it.trim();
if (!pm.getPlugin(it)) {"Looking UpdateCenter for " + it)
if (!initialized) {
initialized = true
def plugin = uc.getPlugin(it)
if (plugin) {"Installing " + it)
def installFuture = plugin.deploy()
while(!installFuture.isDone()) {"Waiting for plugin install: " + it)
installed = true
println("Plugins Count after Installation: "+Jenkins.instance.pluginManager.plugins.size())
println("Zero Plugins specified in pluginslist.cfg file, skipping installation step")
println("File Not Present @ Path: "+filepath)
if (installed) {"Plugins installed, initiating jenkins restart...!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment