Jenkins REST API - 使用树来引用 JSON 数组中的特定项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17236710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins REST API - using tree to reference specific item in JSON array
提问by mckeejm
I am able to use the Jenkins API to get information about my build via the url
我可以使用 Jenkins API 通过 url 获取有关我的构建的信息
http://localhost:8080/job/myjob/149/api/json
I want to be able to query the changeSet node using the tree query string parameter. I can successfully query non-indexed nodes like "duration" via
我希望能够使用树查询字符串参数查询 changeSet 节点。我可以通过以下方式成功查询非索引节点,例如“持续时间”
http://localhost:8080/job/myjob/149/api/json?tree=duration
How do I query indexed nodes like changeSet? I can't seem to find any doc anywhere.
如何查询诸如changeSet之类的索引节点?我似乎在任何地方都找不到任何文档。
{
"actions": [
{
"causes": [
{
"shortDescription": "Started by an SCM change"
}
]
},
{},
{},
{}
],
"artifacts": [],
"building": false,
"description": null,
"duration": 80326,
"estimatedDuration": 68013,
"executor": null,
"fullDisplayName": "my project #149",
"id": "2013-06-14_14-31-06",
"keepLog": false,
"number": 149,
"result": "SUCCESS",
"timestamp": 1371234666000,
"url": "http://localhost:8080/job/my project/149/",
"builtOn": "",
"changeSet": {
"items": [
{
"affectedPaths": [
"SearchViewController.m",
"Sample.strings"
],
"author": {
"absoluteUrl": "http://localhost:8080/user/my user",
"fullName": "My User"
},
"commitId": "9032",
"timestamp": 1371234304048,
"date": "2013-06-14T18:25:04.048031Z",
"msg": "Author:my_author Description: changes Id: B-186199 Reviewer:reviewer_name",
"paths": [
{
"editType": "edit",
"file": "/branches/project_name/iOS/_MainLine/project_name/SearchViewController.m"
},
],
"revision": 9032,
"user": "user_name"
}
],
"kind": "svn",
"revisions": [
{
"module": "repo_url",
"revision": 8953
},
{
"module": "repo_url",
"revision": 9032
}
]
},
"culprits": [
{
"absoluteUrl": "http://localhost:8080/user/username",
"fullName": "username"
}
]
}
回答by Dave Bacher
The API documentation has a hint:
API 文档有一个提示:
A newer alternative is the tree query parameter. [snip] you need only know what elements you are looking for, rather than what you are not looking for (which is anyway an open-ended list when plugins can contribute API elements). The value should be a list of property names to include, with subproperties inside square braces.
更新的替代方法是树查询参数。[snip] 你只需要知道你在找什么元素,而不是你不找什么(当插件可以贡献 API 元素时,这是一个开放式列表)。该值应该是要包含的属性名称列表,子属性在方括号内。
For a simple list, get the whole subtree with:
对于一个简单的列表,使用以下命令获取整个子树:
http://jenkins/job/myjob/../api/json?tree=artifacts[*]
or list specific properties within the braces.
或列出大括号内的特定属性。
For changeSet, use
对于changeSet,使用
http://jenkins/job/myjob/../api/json?tree=changeSet[*[*]]
to retrieve everything.
取回一切。
Use nested square braces for specific sub-subproperties, e.g.:
对特定的子属性使用嵌套方括号,例如:
http://jenkins/job/myjob/../api/json?tree=changeSet[items[revision]]
The tree documentation says that it's intended for cases where the caller doesn't know what properties to retrieve.
树文档说它适用于调用者不知道要检索哪些属性的情况。

