Jenkins REST API-使用树来引用JSON数组中的特定项目 [英] Jenkins REST API - using tree to reference specific item in JSON array
问题描述
我能够使用Jenkins API通过url获取有关我的构建的信息
I am able to use the Jenkins API to get information about my build via the url
http://localhost:8080/job/myjob/149/api/json
我希望能够使用树查询字符串参数查询changeSet节点.我可以通过
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
http://localhost:8080/job/myjob/149/api/json?tree=duration
如何查询诸如changeSet之类的索引节点?我似乎在任何地方都找不到文档.
How do I query indexed nodes like changeSet? I can't seem to find any doc anywhere.
{
"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"
}
]
}
推荐答案
API文档有一个提示:
The API documentation has a hint:
树查询参数是一种较新的替代方法. [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.
对于changeSet
,使用
http://jenkins/job/myjob/../api/json?tree=changeSet[*[*]]
检索所有内容.
对特定的子子属性使用嵌套的方括号,例如:
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.
这篇关于Jenkins REST API-使用树来引用JSON数组中的特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!