如何使用Rally Ruby API访问自定义字段

时间:2013-08-27 23:45:47

标签: ruby rally

Rally工件上有一个自定义字段,在WS API文档中显示为c_MyCustomField

但不打印:

results = @rally.find(query)

results.each do |d|
       puts "Name: #{d["Name"]}, FormattedID: #{d["FormattedID"]}, Owner: #{d["Owner"]["UserName"]}, MyCustomField: #{d["c_MyCustomField"]}"
       d.read
end

1 个答案:

答案 0 :(得分:0)

首先,检查是否正在获取字段:

query.fetch = "c_MyCustomField"

接下来,如果使用v2.0,则必须显式设置WS API版本。

c_前缀特定于WS API版本v2.0。 默认情况下,rally_api将使用WS API的先前版本。 如果您没有在代码中明确指定WS API版本,请参阅WS API早期版本中引用的自定义字段,而不是c _:

results.each do |d|
    puts "MyCustomField: #{d["MyCustomField"]}"
    d.read
end

如果在代码中设置了最新版本的WS API:

config[:version] = "v2.0"

然后自定义字段应该在它前面有c_:

results.each do |d|
    puts "MyCustomField: #{d["c_MyCustomField"]}"
    d.read
end

这假设您正在使用RallyRestTookitForRuby和最新的rally_api gem。

gem list -l

应列出rally_api 0.9.20

请注意,不再支持较旧的rally_rest_api。它也不适用于WS API的v2.0。

这是一个ruby脚本示例:

require 'rally_api'

#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "My Utility"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"

# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user@co.com"
config[:password] = "secret"
config[:workspace] = "W1"
config[:project] = "P1"
config[:version] = "v2.0"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()

@rally = RallyAPI::RallyRestJson.new(config)

query = RallyAPI::RallyQuery.new()
query.type = :defect
query.fetch = "c_MyCustomField"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/1111.js" } #optional
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222.js" } #Team Group 1 from Product 2
query.page_size = 200 #optional - default is 200
query.limit = 1000 #optional - default is 99999
query.project_scope_up = false
query.project_scope_down = true
query.order = "Name Asc"
query.query_string = "(Owner.UserName = someuser@co.com)"

results = @rally.find(query)

results.each do |d|
    puts "MyCustomField: #{d["c_MyCustomField"]}"
    d.read
end