class JenkinsAPIException(Exception):
+
"""
Base class for all errors
"""
class NotFound(JenkinsAPIException):
+
"""
Resource cannot be found
"""
class ArtifactsMissing(NotFound):
+
"""
Cannot find a build with all of the required artifacts.
"""
class UnknownJob(KeyError, NotFound):
+
"""
Jenkins does not recognize the job requested.
"""
class UnknownView(KeyError, NotFound):
+
"""
Jenkins does not recognize the view requested.
"""
class UnknownNode(KeyError, NotFound):
+
"""
Jenkins does not recognize the node requested.
"""
class UnknownQueueItem(KeyError, NotFound):
+
"""
Jenkins does not recognize the requested queue item
"""
class UnknownPlugin(KeyError, NotFound):
+
"""
Jenkins does not recognize the plugin requested.
"""
class NoBuildData(NotFound):
+
"""
A job has no build data.
"""
class NotBuiltYet(NotFound):
+
"""
A job has no build data.
"""
class ArtifactBroken(JenkinsAPIException):
+
"""
An artifact is broken, wrong
"""
class TimeOut(JenkinsAPIException):
+
"""
Some jobs have taken too long to complete.
"""
class NoResults(JenkinsAPIException):
+
"""
A build did not publish any results.
"""
class FailedNoResults(NoResults):
+
"""
A build did not publish any results because it failed
"""
class BadURL(ValueError, JenkinsAPIException):
+
"""
A URL appears to be broken
"""
class NotAuthorized(JenkinsAPIException):
+
"""Not Authorized to access resource"""
# Usually thrown when we get a 403 returned
pass
class NotSupportSCM(JenkinsAPIException):
+
"""
It's a SCM that does not supported by current version of jenkinsapi
"""
class NotConfiguredSCM(JenkinsAPIException):
+
"""
It's a job that doesn't have configured SCM
"""
class NotInQueue(JenkinsAPIException):
+
"""
It's a job that is not in the queue
"""
class PostRequired(JenkinsAPIException):
+
"""
Method requires POST and not GET
"""
pass
+
+
+class BadParams(JenkinsAPIException):
+
+ """
+ Invocation was given bad or inappropriate params
+ """
+ pass
NotInQueue,
NotSupportSCM,
UnknownQueueItem,
+ BadParams,
)
SVN_URL = './scm/locations/hudson.scm.SubversionSCM_-ModuleLocation/remote'
def invoke(self, securitytoken=None, block=False, build_params=None, cause=None, files=None, delay=5):
assert isinstance(block, bool)
+ if build_params and (not self.has_params()):
+ raise BadParams("This job does not support parameters")
+
+ params = {} # Via Get string
+
+ if securitytoken:
+ params['token'] = securitytoken
# Either copy the params dict or make a new one.
build_params = build_params and dict(
build_params.items()) or {} # Via POSTed JSON
- params = {} # Via Get string
url = self.get_build_triggerurl()
- # If job has file parameters - it must be triggered
- # using "/build", not by "/buildWithParameters"
- # "/buildWithParameters" will ignore non-file parameters
- if files:
- url = "%s/build" % self.baseurl
-
if cause:
build_params['cause'] = cause
- if securitytoken:
- params['token'] = securitytoken
-
- build_params['json'] = self.mk_json_from_build_parameters(
- build_params, files)
- data = build_params
+ data = {'json': self.mk_json_from_build_parameters(
+ build_params, files)}
response = self.jenkins.requester.post_url(
url,
)
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)
+
+ # It's possible that an error triggering the build will cause Jenkins
+ # not build, the signal is that we will be redirected to something
+ # other than a QueueItem URL.
+ if not redirect_url.startswith("%s/queue/item" % self.jenkins.baseurl):
+ raise ValueError("Not a Queue URL: %s" % redirect_url)
+
+ qi = QueueItem(redirect_url, self.jenkins)
+ if block:
+ qi.block_until_complete(delay=delay)
+ return qi
def _buildid_for_type(self, buildtype):
"""Gets a buildid for a given type of build"""
return "%s/item/%i" % (self.baseurl, item["id"])
def delete_item(self, queue_item):
- self.delete_item_by_id(queue_item.id)
+ self.delete_item_by_id(queue_item.queue_id)
def delete_item_by_id(self, item_id):
deleteurl = '%s/cancelItem?id=%s' % (self.baseurl, item_id)
from jenkinsapi_tests.test_utils.random_strings import random_string
from jenkinsapi_tests.systests.job_configs import LONG_RUNNING_JOB
from jenkinsapi_tests.systests.job_configs import SHORTISH_JOB, EMPTY_JOB
+from jenkinsapi.custom_exceptions import BadParams
log = logging.getLogger(__name__)
build_number = qq.get_build_number()
self.assertEquals(build_number, invocation + 1)
+ def test_give_params_on_non_parameterized_job(self):
+ job_name = 'Ecreate_%s' % random_string()
+ job = self.jenkins.create_job(job_name, EMPTY_JOB)
+ with self.assertRaises(BadParams):
+ job.invoke(build_params={'foo':'bar', 'baz':99})
+
if __name__ == '__main__':
# logging.basicConfig()
get_data.return_value = TestJob.URL_DATA[url].copy()
j = Job('http://halob:8080/job/foo/', 'foo', self.J)
+ self.assertTrue(j.has_params())
params = j.get_params_list()
self.assertIsInstance(params, list)
self.assertEquals(len(params), 2)
self.assertEquals(params, ['param1', 'param2'])
-
+
def test_get_build(self):
buildnumber = 1
with mock.patch('jenkinsapi.job.Build') as build_mock: