fixed error in Job.is_running in case when there is no any builds of this job
authorAnton V. Yanchenko <simplylizz@gmail.com>
Wed, 30 May 2012 12:06:50 +0000 (16:06 +0400)
committerAnton V. Yanchenko <simplylizz@gmail.com>
Wed, 30 May 2012 12:06:50 +0000 (16:06 +0400)
jenkinsapi/job.py

index 210bab84aca8b8deffcfabad5cc118a390e79be1..8a8fa20e034a728cedb326d127edd8c21ab530d3 100644 (file)
@@ -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'''