Skip to content

Commit

Permalink
Merge pull request #148 from scotje/job_build
Browse files Browse the repository at this point in the history
Make Client::Job.build only request current build number if passed build_start_timeout option.
  • Loading branch information
arangamani committed Nov 5, 2014
2 parents da43a0c + 15a4846 commit b936f98
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 @@ -797,11 +797,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 @@ -384,15 +384,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 b936f98

Please sign in to comment.