Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

Jenkins REST API - using tree to reference specific item in JSON array

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

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

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"
        }
    ]
}
question from:https://stackoverflow.com/questions/17236710/jenkins-rest-api-using-tree-to-reference-specific-item-in-json-array

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The API documentation has a hint:

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.

For changeSet, use

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...