From bc3544c9a82be2fd8cc889761ad9b60dfe4f8931 Mon Sep 17 00:00:00 2001 From: Vladimir Bogatyrev Date: Tue, 1 Oct 2013 15:42:25 +0400 Subject: [PATCH] Add the method for retrieving the last stable build --- jenkinsapi/job.py | 14 ++++++++++++++ jenkinsapi_tests/unittests/test_job.py | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py index d5e1b69..ce8a310 100644 --- a/jenkinsapi/job.py +++ b/jenkinsapi/job.py @@ -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 diff --git a/jenkinsapi_tests/unittests/test_job.py b/jenkinsapi_tests/unittests/test_job.py index 4a74ba6..82e7e21 100644 --- a/jenkinsapi_tests/unittests/test_job.py +++ b/jenkinsapi_tests/unittests/test_job.py @@ -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): -- 2.34.1