Cut out some more crap, but noticed that invocation of parameterized
authorSalim Fadhley <sal@stodge.org>
Sun, 3 Aug 2014 00:28:26 +0000 (01:28 +0100)
committerSalim Fadhley <sal@stodge.org>
Sun, 3 Aug 2014 00:28:26 +0000 (01:28 +0100)
builds is broken.

examples/how_to/delete_all_the_nodes_except_master.py [new file with mode: 0644]
jenkinsapi/custom_exceptions.py
jenkinsapi/job.py
jenkinsapi/nodes.py
jenkinsapi/queue.py
jenkinsapi_tests/systests/test_invocation.py
jenkinsapi_tests/systests/test_parameterized_builds.py

diff --git a/examples/how_to/delete_all_the_nodes_except_master.py b/examples/how_to/delete_all_the_nodes_except_master.py
new file mode 100644 (file)
index 0000000..e68c89a
--- /dev/null
@@ -0,0 +1,11 @@
+import logging
+logging.basicConfig()
+
+from jenkinsapi.jenkins import Jenkins
+
+j = Jenkins('http://localhost:8080')
+
+for node_id, _ in j.get_nodes().iteritems():
+    if not node_id == 'master':
+        print(node_id)
+        j.delete_node(node_id)
index f3bf28627d55f13fb67454ba29f7019400d376a6..69009addbb1d25c23f77d3508b744d5493b0a23a 100644 (file)
@@ -87,13 +87,6 @@ class TimeOut(JenkinsAPIException):
     pass
 
 
-class WillNotBuild(JenkinsAPIException):
-    """
-    Cannot trigger a new build.
-    """
-    pass
-
-
 class NoResults(JenkinsAPIException):
     """
     A build did not publish any results.
index c3b9e9fe4bda16574d07a5bd8a8d64d5c7481a64..f6aabc8e1c2537a7b0b58488f899897aebcaea16 100644 (file)
@@ -13,11 +13,9 @@ except ImportError:
 
 import xml.etree.ElementTree as ET
 from collections import defaultdict
-from time import sleep
 from jenkinsapi.build import Build
 from jenkinsapi.queue import QueueItem
 from jenkinsapi.jenkinsbase import JenkinsBase
-from jenkinsapi.queue import QueueItem
 from jenkinsapi.mutable_jenkins_thing import MutableJenkinsThing
 from jenkinsapi.custom_exceptions import (
     NoBuildData,
@@ -25,7 +23,6 @@ from jenkinsapi.custom_exceptions import (
     NotFound,
     NotInQueue,
     NotSupportSCM,
-    WillNotBuild,
     UnknownQueueItem,
 )
 
@@ -166,7 +163,7 @@ class Job(JenkinsBase, MutableJenkinsThing):
                                                                file_params)
         return json.dumps(to_json_structure)
 
-    def invoke(self, securitytoken=None, block=False, build_params=None, cause=None, files=None):
+    def invoke(self, securitytoken=None, block=False, build_params=None, cause=None, files=None, delay=5):
         assert isinstance(block, bool)
 
         # Either copy the params dict or make a new one.
@@ -198,12 +195,13 @@ class Job(JenkinsBase, MutableJenkinsThing):
             files=files,
         )
 
-        queue_url = response.headers['location']
-        qi = QueueItem(queue_url, self.jenkins)
-
-        if block:
-            qi.block_until_complete(delay=10)
-        return qi
+        redirect_url = response.headers['location']
+        if redirect_url.startswith("%s/queue/item" % self.jenkins.baseurl):
+            qi = QueueItem(redirect_url, self.jenkins)
+            if block:
+                qi.block_until_complete(delay=delay)
+            return qi
+        raise ValueError("Not a Queue URL: %s" % redirect_url)
 
     def _buildid_for_type(self, buildtype):
         """Gets a buildid for a given type of build"""
index 82fbe705d3631facf1d2a371089ab15634606f8e..a3bd036c0d27581f5504790154a8bcfa390ab612 100644 (file)
@@ -45,11 +45,7 @@ class Nodes(JenkinsBase):
                 nodeurl = '%s/(%s)' % (self.baseurl, nodename)
             else:
                 nodeurl = '%s/%s' % (self.baseurl, nodename)
-            try:
-                yield item['displayName'], Node(nodeurl, nodename, self.jenkins)
-            except Exception:
-                import ipdb
-                ipdb.set_trace()
+            yield item['displayName'], Node(nodeurl, nodename, self.jenkins)
 
     def __getitem__(self, nodename):
         self_as_dict = dict(self.iteritems())
index 523b4b77a7e943698fc1aacb5398b37b1d65b59b..7c04bb5c7649337c41d68e695af3227e286c3540 100644 (file)
@@ -90,9 +90,13 @@ class QueueItem(JenkinsBase):
         JenkinsBase.__init__(self, baseurl)
 
     @property
-    def id(self):
+    def queue_id(self):
         return self._data['id']
 
+    @property
+    def name(self):
+        return self._data['task']['name']
+
     def get_jenkins_obj(self):
         return self.jenkins
 
@@ -117,7 +121,7 @@ class QueueItem(JenkinsBase):
                                self.__class__.__name__, str(self))
 
     def __str__(self):
-        return "%s Queue #%i" % (self._data['name'], self._data['id'])
+        return "%s Queue #%i" % (self.name, self.queue_id)
 
     def get_build(self):
         build_number = self.get_build_number()
index 1d1cbb8420ae6dadd94f74c9065198ce5d04016b..69e03aa16503185e65d615d9973dac29e3e8a965 100644 (file)
@@ -22,7 +22,7 @@ log = logging.getLogger(__name__)
 class TestInvocation(BaseSystemTest):
 
     def test_invocation_object(self):
-        job_name = 'create_%s' % random_string()
+        job_name = 'Acreate_%s' % random_string()
         job = self.jenkins.create_job(job_name, SHORTISH_JOB)
         qq = job.invoke()
         self.assertIsInstance(qq, QueueItem)
@@ -31,7 +31,7 @@ class TestInvocation(BaseSystemTest):
         self.assertEquals(qq.get_build_number(), 1)
 
     def test_get_block_until_build_running(self):
-        job_name = 'create_%s' % random_string()
+        job_name = 'Bcreate_%s' % random_string()
         job = self.jenkins.create_job(job_name, LONG_RUNNING_JOB)
         qq = job.invoke()
         time.sleep(3)
@@ -50,14 +50,14 @@ class TestInvocation(BaseSystemTest):
         self.assertIn('Started by user', console)
  
     def test_get_block_until_build_complete(self):
-        job_name = 'create_%s' % random_string()
+        job_name = 'Ccreate_%s' % random_string()
         job = self.jenkins.create_job(job_name, SHORTISH_JOB)
         qq = job.invoke()
         qq.block_until_complete()
         self.assertFalse(qq.get_build().is_running())
  
     def test_multiple_invocations_and_get_last_build(self):
-        job_name = 'create_%s' % random_string()
+        job_name = 'Dcreate_%s' % random_string()
  
         job = self.jenkins.create_job(job_name, SHORTISH_JOB)
  
@@ -72,7 +72,7 @@ class TestInvocation(BaseSystemTest):
         self.assertIsInstance(build, Build)
  
     def test_multiple_invocations_and_get_build_number(self):
-        job_name = 'create_%s' % random_string()
+        job_name = 'Ecreate_%s' % random_string()
  
         job = self.jenkins.create_job(job_name, EMPTY_JOB)
  
index d13224fbaed5642651e60ac362ebe6a33b04283f..cc25539412853b13d09f2ed0ba6fa1370bdeff50 100644 (file)
@@ -16,7 +16,6 @@ from jenkinsapi_tests.test_utils.random_strings import random_string
 from jenkinsapi_tests.systests.job_configs import JOB_WITH_FILE
 from jenkinsapi_tests.systests.job_configs import JOB_WITH_FILE_AND_PARAMS
 from jenkinsapi_tests.systests.job_configs import JOB_WITH_PARAMETERS
-from jenkinsapi.custom_exceptions import WillNotBuild
 
 
 class TestParameterizedBuilds(BaseSystemTest):
@@ -25,11 +24,11 @@ class TestParameterizedBuilds(BaseSystemTest):
         file_data = random_string()
         param_file = StringIO(file_data)
 
-        job_name = 'create_%s' % random_string()
+        job_name = 'create1_%s' % random_string()
         job = self.jenkins.create_job(job_name, JOB_WITH_FILE)
-        job.invoke(block=True, files={'file.txt': param_file})
+        item = job.invoke(block=True, files={'file.txt': param_file})
 
-        build = job.get_last_build()
+        build = job.poll().get_last_build()
         while build.is_running():
             time.sleep(0.25)
 
@@ -40,20 +39,20 @@ class TestParameterizedBuilds(BaseSystemTest):
 
 #     def test_invoke_job_parameterized(self):
 #         param_B = random_string()
-# 
-#         job_name = 'create_%s' % random_string()
+#  
+#         job_name = 'create2_%s' % random_string()
 #         job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)
 #         job.invoke(block=True, build_params={'B': param_B})
-# 
+#  
 #         build = job.get_last_build()
 #         while build.is_running():
 #             time.sleep(0.25)
-# 
+#  
 #         artifacts = build.get_artifact_dict()
 #         self.assertIsInstance(artifacts, dict)
 #         artB = artifacts['b.txt']
 #         self.assertTrue(artB.get_data().strip(), param_B)
-# 
+#  
 #         self.assertIn(param_B, build.get_console())
 # 
 #     def test_parameterized_job_build_queuing(self):