From fecee408ddb9a9b8ca551d8c92d30a5203542d0c Mon Sep 17 00:00:00 2001 From: Aleksey Maksimov Date: Mon, 5 Aug 2013 00:00:50 +0800 Subject: [PATCH] Fixed problem with get_build_number (Issue #158) --- jenkinsapi/invocation.py | 3 +++ jenkinsapi_tests/systests/test_invocation.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/jenkinsapi/invocation.py b/jenkinsapi/invocation.py index f014ff2..6ab1800 100644 --- a/jenkinsapi/invocation.py +++ b/jenkinsapi/invocation.py @@ -47,6 +47,9 @@ class Invocation(object): """ If this job is building or complete then provide it's build-number """ + # print '\nDEBUG: job.get_last_build_or_none=', self.job.get_last_build_or_none() + if not self.job.is_queued_or_running(): + self.build_number = self.job.get_last_buildnumber() return self.build_number def get_build(self): diff --git a/jenkinsapi_tests/systests/test_invocation.py b/jenkinsapi_tests/systests/test_invocation.py index 8d9bfb7..0e220fe 100644 --- a/jenkinsapi_tests/systests/test_invocation.py +++ b/jenkinsapi_tests/systests/test_invocation.py @@ -6,7 +6,8 @@ from jenkinsapi.build import Build from jenkinsapi.invocation import Invocation from jenkinsapi_tests.systests.base import BaseSystemTest from jenkinsapi_tests.test_utils.random_strings import random_string -from jenkinsapi_tests.systests.job_configs import LONG_RUNNING_JOB, SHORTISH_JOB, EMPTY_JOB +from jenkinsapi_tests.systests.job_configs import LONG_RUNNING_JOB +from jenkinsapi_tests.systests.job_configs import SHORTISH_JOB, EMPTY_JOB class TestInvocation(BaseSystemTest): @@ -56,6 +57,16 @@ class TestInvocation(BaseSystemTest): build = job.get_build(build_number) self.assertIsInstance(build, Build) + def test_multiple_invocations_and_get_build_number(self): + job_name = 'create_%s' % random_string() + + job = self.jenkins.create_job(job_name, EMPTY_JOB) + + for invocation in range(3): + ii = job.invoke() + ii.block(until='completed') + build_number = ii.get_build_number() + self.assertEquals(build_number, invocation+1) if __name__ == '__main__': -- 2.34.1