From d9845d205b1c794210af7493587aa9527faa5625 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 11 Jun 2013 16:38:47 -0500 Subject: [PATCH] Adding API Method - Build Job Added a new method to the api for building a job with params Job.py was modified to respond better to failures build.py was modified to be in sync with the remove of .id() on almost all classes --- jenkinsapi/build.py | 2 +- jenkinsapi/jenkins.py | 10 ++++++++++ jenkinsapi/job.py | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/jenkinsapi/build.py b/jenkinsapi/build.py index e676cac..589b3e5 100644 --- a/jenkinsapi/build.py +++ b/jenkinsapi/build.py @@ -226,7 +226,7 @@ class Build(JenkinsBase): count = 0 while self.is_running(): total_wait = delay * count - log.info("Waited %is for %s #%s to complete" % ( total_wait, self.job.id(), self.id() ) ) + log.info("Waited %is for %s #%s to complete" % ( total_wait, self.job.name, self.name ) ) sleep( delay ) count += 1 diff --git a/jenkinsapi/jenkins.py b/jenkinsapi/jenkins.py index b8fae2d..86f9889 100644 --- a/jenkinsapi/jenkins.py +++ b/jenkinsapi/jenkins.py @@ -163,6 +163,16 @@ class Jenkins(JenkinsBase): data='') self.poll() return self[jobname] + + def build_job(self, jobname, params={}): + """ + Invoke a build by job name + :param jobname: name of exist job, str + :param params: the job params, dict + :return: none + """ + self[jobname].invoke(params=params) + return def delete_job(self, jobname): """ diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py index 49a40e8..d7d8889 100644 --- a/jenkinsapi/job.py +++ b/jenkinsapi/job.py @@ -119,8 +119,10 @@ class Job(JenkinsBase, MutableJenkinsThing): log.info( "%s is running.", self.name ) elif original_build_no < self.get_last_buildnumber(): log.info( "%s has completed.", self.name ) + elif not response.ok : + response.raise_for_status() else: - raise AssertionError("The job did not schedule.") + raise AssertionError("The job did not schedule. REASON:%s" % response.reason) def _buildid_for_type(self, buildtype): """Gets a buildid for a given type of build""" -- 2.7.4