使用jenkins_api_client从Jenkins API获取构建信息

时间:2013-06-20 08:20:59

标签: ruby-on-rails ruby json jenkins

我正在编写一个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中获得BUILDCLIENT值,例如APACHEGOOGLE

2 个答案:

答案 0 :(得分:0)

如果您遗漏了jenkins_api_client ruby​​gem中的某项功能,请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.