jenkins_launcher can now install plugins
authorSudharshan S <sudharsh@gmail.com>
Tue, 25 Jun 2013 16:20:26 +0000 (21:50 +0530)
committerSudharshan S <sudharsh@gmail.com>
Wed, 26 Jun 2013 09:34:35 +0000 (15:04 +0530)
install_plugin takes in a URL or a list of URLs and restarts jenkins thereby installing the plugins

jenkinsapi_utils/jenkins_launcher.py

index 5918d18..9c1a938 100644 (file)
@@ -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()