json - Jenkins REST API - 使用树来引用 JSON 数组中的特定项目

标签 json rest jenkins

我可以使用 Jenkins API 通过 url 获取有关我的构建的信息

http://localhost:8080/job/myjob/149/api/json

我希望能够使用树查询字符串参数来查询 changeSet 节点。我可以通过

成功查询“持续时间”等非 inode
http://localhost:8080/job/myjob/149/api/json?tree=duration

如何查询像 changeSet 这样的 inode ?我似乎在任何地方都找不到任何文档。

{
    "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 文档有提示:

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.

对于一个简单的列表,获取整个子树:

http://jenkins/job/myjob/../api/json?tree=artifacts[*]

或在大括号内列出特定属性。

对于 changeSet,使用

http://jenkins/job/myjob/../api/json?tree=changeSet[*[*]]

检索所有内容。

对特定的子子属性使用嵌套的方括号,例如:

http://jenkins/job/myjob/../api/json?tree=changeSet[items[revision]]

树文档说它适用于调用者不知道要检索哪些属性的情况。

关于json - Jenkins REST API - 使用树来引用 JSON 数组中的特定项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17236710/

相关文章:

javascript - 如何使用 jquery 或 javascript 重新定位 JSON 中对象的键

rest - 自定义 ObjectMapper 不适用于 spring boot hateoas

git - 如何仅在特定文件集发生更改时触发构建

groovy - 如何使用 Groovy 在 Jenkins 中获取有关当前构建项目的特定信息?

javascript - Microsoft Edge 浏览器缓存中的 RESTful Angular 应用

jenkins - 在 Linux Jenkins 上构建一个针对 MSVC 的项目

php - android与MYSQL数据库连接返回null值

json - logstash_forwarder已连接到Lostash服务器IP,但从未收到事件

java - 如何从 JSON 响应中获取所有属性名称(嵌套或非嵌套)

java - SOAP 使用适配器休息服务