From: Sudharshan S Date: Tue, 25 Jun 2013 16:20:26 +0000 (+0530) Subject: jenkins_launcher can now install plugins X-Git-Tag: v0.2.23~121^2~8^2^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c003fd87a8c5ad61743a78db47f805ea4dc40a55;p=tools%2Fpython-jenkinsapi.git jenkins_launcher can now install plugins install_plugin takes in a URL or a list of URLs and restarts jenkins thereby installing the plugins --- diff --git a/jenkinsapi_utils/jenkins_launcher.py b/jenkinsapi_utils/jenkins_launcher.py index 5918d18..9c1a938 100644 --- a/jenkinsapi_utils/jenkins_launcher.py +++ b/jenkinsapi_utils/jenkins_launcher.py @@ -1,5 +1,6 @@ import os import time +import urllib import Queue import shutil import logging @@ -69,6 +70,22 @@ class JenkinsLancher(object): config_source = pkg_resources.resource_string('jenkinsapi_tests.systests', 'config.xml') config_dest_file.write(config_source.encode('UTF-8')) + def install_plugin(self, hpi_url): + plugin_dir = os.path.join(self.jenkins_home, 'plugins') + if not os.path.exists(plugin_dir): + os.mkdir(plugin_dir) + hpi_url = [hpi_url] if isinstance(hpi_url, basestring) else hpi_url + for i,url in enumerate(hpi_url): + log.info("Downloading %s", url) + log.info("Plugins will be installed in '%s'" % plugin_dir) + # FIXME: This is kinda ugly but works + filename = "plugin_%s.hpi" % i + urllib.urlretrieve(url, os.path.join(plugin_dir, filename)) + log.info("Restarting Jenkins after installing the plugins") + self.jenkins_process.terminate() + self.jenkins_process.wait() + self.start() + def stop(self): log.info("Shutting down jenkins.") self.jenkins_process.terminate()