adding support for stopping a build if it's running
authorVictor García <victor@tuenti.com>
Thu, 21 Mar 2013 13:09:59 +0000 (14:09 +0100)
committerVictor García <victor@tuenti.com>
Thu, 21 Mar 2013 13:09:59 +0000 (14:09 +0100)
jenkinsapi/build.py
jenkinsapi/job.py

index d0a2277..74e0df9 100644 (file)
@@ -1,3 +1,5 @@
+import urlparse
+import urllib2
 from jenkinsapi.artifact import Artifact
 from jenkinsapi import config
 from jenkinsapi.jenkinsbase import JenkinsBase
@@ -260,3 +262,20 @@ class Build(JenkinsBase):
 
     def get_timestamp(self):
         return self._data['timestamp']
+
+    def stop(self):
+        """
+        Stops the build execution if it's running
+        :return boolean True if succeded False otherwise or the build is not running
+        """
+        if not self.is_running():
+            return False
+
+        stopbuildurl = urlparse.urljoin(self.baseurl, 'stop')
+        try:
+            self.post_data(stopbuildurl, '')
+        except urllib2.HTTPError:
+            # The request doesn't have a response, so it returns 404,
+            # it's the expected behaviour
+            pass
+        return True
index 6da961b..b2b2767 100644 (file)
@@ -394,6 +394,10 @@ class Job(JenkinsBase):
         return self.post_data(enableurl, '')
 
     def delete_from_queue(self):
+        """
+        Delete a job from the queue only if it's enqueued
+        :raise NotInQueue if the job is not in the queue
+        """
         if not self.is_queued():
             raise NotInQueue()
         queue_id = self._data['queueItem']['id']