From 15a484670021cd73b226cb24daac1aac14c55cce Mon Sep 17 00:00:00 2001 From: Jesse Scott Date: Thu, 2 Oct 2014 11:13:09 -0700 Subject: [PATCH] Make Client::Job.build only request current build number if passed build_start_timeout option. --- lib/jenkins_api_client/job.rb | 12 +++++++----- spec/unit_tests/job_spec.rb | 4 ---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/jenkins_api_client/job.rb b/lib/jenkins_api_client/job.rb index 347bafd8..ccc6df9f 100644 --- a/lib/jenkins_api_client/job.rb +++ b/lib/jenkins_api_client/job.rb @@ -772,11 +772,13 @@ def build(job_name, params={}, opts = {}) msg << " with parameters: #{params.inspect}" unless params.empty? @logger.info msg - # Best-guess build-id - # This is only used if we go the old-way below... but we can use this number to detect if multiple - # builds were queued - current_build_id = get_current_build_number(job_name) - expected_build_id = current_build_id > 0 ? current_build_id + 1 : 1 + if (opts['build_start_timeout'] || 0) > 0 + # Best-guess build-id + # This is only used if we go the old-way below... but we can use this number to detect if multiple + # builds were queued + current_build_id = get_current_build_number(job_name) + expected_build_id = current_build_id > 0 ? current_build_id + 1 : 1 + end if (params.nil? or params.empty?) response = @client.api_post_request("/job/#{path_encode job_name}/build", diff --git a/spec/unit_tests/job_spec.rb b/spec/unit_tests/job_spec.rb index 921a1437..f35ce732 100644 --- a/spec/unit_tests/job_spec.rb +++ b/spec/unit_tests/job_spec.rb @@ -383,15 +383,11 @@ describe "#build" do # First tests confirm the build method works the same as it used to it "accepts the job name and builds the job" do - @client.should_receive(:api_get_request).with( - "/job/test_job").and_return({}) @client.should_receive(:api_post_request).with( "/job/test_job/build", {}, true).and_return(FakeResponse.new(302)) @job.build("test_job").should == '302' end it "accepts the job name with params and builds the job" do - @client.should_receive(:api_get_request).with( - "/job/test_job").and_return({}) @client.should_receive(:api_post_request).with( "/job/test_job/buildWithParameters", {:branch => 'feature/new-stuff'},