Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Client::Job.build only request current build number if passed build_start_timeout option. #148

Merged
merged 1 commit into from
Nov 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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