Skip to content

Commit

Permalink
Make Client::Job.build only request current build number if passed bu…
Browse files Browse the repository at this point in the history
…ild_start_timeout option.
  • Loading branch information
scotje committed Oct 2, 2014
1 parent 257d5f8 commit 15a4846
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 7 additions & 5 deletions lib/jenkins_api_client/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions spec/unit_tests/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down

0 comments on commit 15a4846

Please sign in to comment.