From 5624dc62ec59319d1e422c386f850184c016847c Mon Sep 17 00:00:00 2001 From: "Anton V. Yanchenko" Date: Wed, 30 May 2012 16:06:50 +0400 Subject: [PATCH] fixed error in Job.is_running in case when there is no any builds of this job --- jenkinsapi/job.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py index 210bab8..8a8fa20 100644 --- a/jenkinsapi/job.py +++ b/jenkinsapi/job.py @@ -146,11 +146,19 @@ class Job(JenkinsBase): def get_last_build( self ): """ - Get the last good build + Get the last build """ bn = self.get_last_buildnumber() return self.get_build( bn ) + def get_last_build_or_none(self): + """ + Get the last build or None if there is no builds + """ + bn = self.get_last_buildnumber() + if bn is not None: + return self.get_build(bn) + def get_last_completed_build( self ): """ Get the last build regardless of status @@ -192,10 +200,12 @@ class Job(JenkinsBase): def is_running(self): self.poll() try: - return self.get_last_build().is_running() + build = self.get_last_build_or_none() + if build is not None: + return build.is_running() except NoBuildData: log.info("No build info available for %s, assuming not running." % str(self) ) - return False + return False def get_config(self): '''Returns the config.xml from the job''' -- 2.34.1