Jenkins REST API - 使用树来引用 JSON 数组中的特定项目 [英] Jenkins REST API - using tree to reference specific item in JSON array

查看:26
本文介绍了Jenkins REST API - 使用树来引用 JSON 数组中的特定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 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 文档有提示:

更新的替代方法是树查询参数.[snip] 你只需要知道你在找什么元素,而不是你不找什么(当插件可以贡献 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.

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆