Reputation: 20293
I'm writing a Jenkins plugin and I want to retrieve last build information (number, timestamp, build parameters) for a given job from the Jenkins API. I can do this using jenkins_api_client (ruby gem) with REST call and obtain it.
<url_to_jenkins>job/<job name>/api/json?pretty=true&tree=builds[actions[parameters[name,value]],id,number]
This is the output I get:
"{""builds""=>
[{""actions""=>
[{""parameters""=>
[{""name""=>""BUILD"", ""value""=>""APACHE""},
{""name""=>""CLIENT"", ""value""=>""GOOGLE""}]}, {}, {}, {}, {}],
""id""=>""2013-03-09_07-36-49"",
""number""=>18}]}"
How can I get BUILD
and CLIENT
values i.e., APACHE
and GOOGLE
in ruby?
Upvotes: 1
Views: 2056
Reputation: 14893
I have not tested it but you require json, this is the format of the answer.
require 'json'
reply = "{""builds""=>
[{""actions""=>
[{""parameters""=>
[{""name""=>""BUILD"", ""value""=>""APACHE""},
{""name""=>""CLIENT"", ""value""=>""GOOGLE""}]}, {}, {}, {}, {}],
""id""=>""2013-03-09_07-36-49"",
""number""=>18}]}".replace('=>', ':')
my_hash = JSON.parse(reply)
puts my_hash['builds'] # access the content and further. you can do that.
Upvotes: 1
Reputation: 365
If you are missing a functionality in the jenkins_api_client rubygem, please open up an issue with detailed description and I'll get that implemented as soon as possible.
Thanks, Kannan (author of jenkins_api_client)
Upvotes: 0