Created
October 9, 2018 18:26
-
-
Save wrossmck/d0d74f9afefe4a69b3992a8090381d28 to your computer and use it in GitHub Desktop.
Install a specific plugin on jenkins master via groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// installs single hardcoded plugin | |
import jenkins.model.* | |
import java.util.logging.Logger | |
def logger = Logger.getLogger("") | |
def installed = false | |
def initialized = false | |
def pluginParameter="apache-httpcomponents-client-4-api" // this could be a parameter if we wanted | |
def plugins = pluginParameter.split() | |
logger.info("" + plugins) | |
def instance = Jenkins.getInstance() | |
def pm = instance.getPluginManager() | |
def uc = instance.getUpdateCenter() | |
plugins.each { | |
logger.info("[plugins] Checking " + it) | |
if (!pm.getPlugin(it)) { | |
logger.info("[plugins] Looking UpdateCenter for " + it) | |
if (!initialized) { | |
uc.updateAllSites() | |
initialized = true | |
} | |
def plugin = uc.getPlugin(it) | |
if (plugin) { | |
logger.info("Installing " + it) | |
def installFuture = plugin.deploy() | |
while(!installFuture.isDone()) { | |
logger.info("[plugins] Waiting for plugin install: " + it) | |
sleep(3000) | |
} | |
installed = true | |
} | |
} | |
} | |
if (installed) { | |
logger.info("Plugins installed, initializing a restart!") | |
instance.save() | |
instance.restart() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment