Add the method for retrieving the last stable build
authorVladimir Bogatyrev <vbogatyrev@griddynamics.com>
Tue, 1 Oct 2013 11:42:25 +0000 (15:42 +0400)
committerVladimir Bogatyrev <vbogatyrev@griddynamics.com>
Thu, 2 Jan 2014 20:24:00 +0000 (00:24 +0400)
jenkinsapi/job.py
jenkinsapi_tests/unittests/test_job.py

index d5e1b6931e17e0606047d955bb6efee5bbd36a16..ce8a310ba77a57cedfb8b1e1a66eec3b9a684a4a 100644 (file)
@@ -207,6 +207,7 @@ class Job(JenkinsBase, MutableJenkinsThing):
         """Gets a buildid for a given type of build"""
         self.poll()
         KNOWNBUILDTYPES = [
+            "lastStableBuild",
             "lastSuccessfulBuild",
             "lastBuild",
             "lastCompletedBuild",
@@ -224,6 +225,12 @@ class Job(JenkinsBase, MutableJenkinsThing):
         """
         return self._buildid_for_type("firstBuild")
 
+    def get_last_stable_buildnumber(self):
+        """
+        Get the numerical ID of the last stable build.
+        """
+        return self._buildid_for_type("lastStableBuild")
+
     def get_last_good_buildnumber(self):
         """
         Get the numerical ID of the last good build.
@@ -284,6 +291,13 @@ class Job(JenkinsBase, MutableJenkinsThing):
         """
         return self._data.get('nextBuildNumber', 0)
 
+    def get_last_stable_build(self):
+        """
+        Get the last stable build
+        """
+        bn = self.get_last_stable_buildnumber()
+        return self.get_build(bn)
+
     def get_last_good_build(self):
         """
         Get the last good build
index 4a74ba64c5d11a5647b51645c73aa8372d83825a..82e7e21c0b4ed74a64c17a0c244181def62f947c 100644 (file)
@@ -117,6 +117,11 @@ class TestJob(unittest.TestCase):
         ret = self.j.get_last_good_buildnumber()
         self.assertTrue(ret, 3)
 
+    @mock.patch.object(JenkinsBase, 'get_data', fakeGetData)
+    def test_get_last_stable_buildnumber(self):
+        ret = self.j.get_last_stable_buildnumber()
+        self.assertTrue(ret, 3)
+
     @mock.patch.object(JenkinsBase, 'get_data', fakeGetData)
     def test_get_last_failed_buildnumber(self):
         with self.assertRaises(NoBuildData):