from jenkinsapi.job import Job
from jenkinsapi.node import Node
from jenkinsapi.view import View
+from jenkinsapi import config
from utils.urlopener import mkurlopener, mkopener, NoAuto302Handler
import cookielib
import logging
log.debug("args: %s" % auth_args)
return auth_args
+ def get_base_server_url(self):
+ return self.baseurl[:-(len(config.JENKINS_API))]
+
def get_opener(self):
if self.formauth:
return self.get_login_opener()
from jenkinsapi.jenkinsbase import JenkinsBase
from jenkinsapi import exceptions
-from exceptions import NoBuildData, NotFound
+from exceptions import NoBuildData, NotFound, NotInQueue
log = logging.getLogger(__name__)
def disable(self):
'''Disable job'''
- disableurl = urlparse.urljoin( self.baseurl, 'disable' )
+ disableurl = urlparse.urljoin(self.baseurl, 'disable' )
return self.post_data(disableurl, '')
def enable(self):
'''Enable job'''
- enableurl = urlparse.urljoin( self.baseurl, 'enable' )
+ enableurl = urlparse.urljoin(self.baseurl, 'enable' )
return self.post_data(enableurl, '')
+
+ def delete_from_queue(self):
+ if not self.is_queued():
+ raise NotInQueue()
+ queue_id = self._data['queueItem']['id']
+ cancelurl = urlparse.urljoin(self.get_jenkins_obj().get_base_server_url(),
+ 'queue/cancelItem?id=%s' % queue_id)
+ try:
+ self.post_data(cancelurl, '')
+ except urllib2.HTTPError:
+ # The request doesn't have a response, so it returns 404,
+ # it's the expected behaviour
+ pass
+ return True
+