我正在编写一个Jenkins插件,我想从Jenkins API中检索给定作业的最后构建信息(数字,时间戳,构建参数)。我可以使用 jenkins_api_client (ruby gem)和REST调用来获取它。
<url_to_jenkins>job/<job name>/api/json?pretty=true&tree=builds[actions[parameters[name,value]],id,number]
这是我得到的输出:
"{""builds""=>
[{""actions""=>
[{""parameters""=>
[{""name""=>""BUILD"", ""value""=>""APACHE""},
{""name""=>""CLIENT"", ""value""=>""GOOGLE""}]}, {}, {}, {}, {}],
""id""=>""2013-03-09_07-36-49"",
""number""=>18}]}"
如何在ruby中获得BUILD
和CLIENT
值,例如APACHE
和GOOGLE
?
答案 0 :(得分:0)
如果您遗漏了jenkins_api_client rubygem中的某项功能,请open up an issue详细说明,我会尽快实施。
谢谢, Kannan(jenkins_api_client的作者)
答案 1 :(得分:0)
我没有测试过,但你需要json,这是答案的格式。
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.