From: Victor GarcĂ­a Date: Thu, 21 Mar 2013 13:09:59 +0000 (+0100) Subject: adding support for stopping a build if it's running X-Git-Tag: v0.2.23~97^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6313fd37cda2cb01c7808052ce4a90f4adfee9a3;p=tools%2Fpython-jenkinsapi.git adding support for stopping a build if it's running --- diff --git a/jenkinsapi/build.py b/jenkinsapi/build.py index d0a2277..74e0df9 100644 --- a/jenkinsapi/build.py +++ b/jenkinsapi/build.py @@ -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 diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py index 6da961b..b2b2767 100644 --- a/jenkinsapi/job.py +++ b/jenkinsapi/job.py @@ -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']