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

Method to get promotions of given job #112

Merged
merged 1 commit into from
Nov 15, 2013
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
25 changes: 25 additions & 0 deletions lib/jenkins_api_client/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,31 @@ def chain(job_names, threshold, criteria, parallel = 1)
filtered_job_names[0..parallel-1]
end

# Get a list of promoted builds for given job
#
# @param [String] job_name
# @return [Hash] Hash map of promitions and the promoted builds. Promotions that didn't took place yet
# return nil
def get_promotions(job_name)
result = {}

@logger.info "Obtaining the promotions of '#{job_name}'"
response_json = @client.api_get_request("/job/#{job_name}/promotion")

response_json["processes"].each do |promotion|
@logger.info "Getting promotion details of '#{promotion['name']}'"

if promotion['color'] == 'notbuilt'
result[promotion['name']] = nil
else
promo_json = @client.api_get_request("/job/#{job_name}/promotion/latest/#{promotion['name']}")
result[promotion['name']] = promo_json['target']['number']
end
end

result
end

private

# Obtains the threshold params used by jenkins in the XML file
Expand Down
19 changes: 19 additions & 0 deletions spec/unit_tests/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,25 @@
end
end

describe "#get_promotions" do
it "accepts the jon name and returns the promotions" do
mock_job_promotions_response = {
"processes" => [ { "name" => "dev",
"url" => "not_required",
"color" => "blue",
},
{ "name" => "stage",
"url" => "not_required",
"color" => "notbuilt",
},
], }

@client.should_receive(:api_get_request).with('/job/test_job/promotion').and_return(
mock_job_promotions_response)
@client.should_receive(:api_get_request).and_return({'target' => {'number' => 42}})
@job.get_promotions("test_job").should == {'dev' => 42, 'stage' => nil}
end
end
end
end
end