Jenkins Java:获取开始构建的用户 [英] Jenkins Java: Get user who started the build

查看:623
本文介绍了Jenkins Java:获取开始构建的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://[JENKINS_NAME]/job/[JOB_NAME]/[BUILD_NUMBER]/

我可以看到由用户[USER_NAME]启动.

我想从我的Java应用程序中获取该用户名.

I want to get that username from my java application.

非常感谢您的帮助.

推荐答案

您可以进行http调用以获取所有这些详细信息.获取这些详细信息的URL是:

You can make a http call to get all these details. URL to get those details is:

http://<Jenkins URL>/job/<job name>/<build number>/api/json

其余的调用之后,您将获得此json.

After the rest call, you will be getting this json.

{
"_class": "hudson.model.FreeStyleBuild",
"actions": [
    {
        "_class": "hudson.model.CauseAction",
        "causes": [
            {
                "_class": "hudson.model.Cause$UserIdCause",
                "shortDescription": "Started by user XXXXXX",
                "userId": "xxx@yyy.com",
                "userName": "ZZZZZZZZ"
            }
        ]
    },
    {},
    {
        "_class": "jenkins.metrics.impl.TimeInQueueAction"
    },
    {},
    {}
],
...
}

因此,您所要做的就是解析此json并获取javavar['actions'][0]['causes'][0]['userName']下的值.绝对是那样.我可能不确定这些索引.您只需尝试找出.希望这会有所帮助.

So All you have do is parse this json and get the value under javavar['actions'][0]['causes'][0]['userName']. Definitely it will be like that only. I maynot be sure about the indexes. You just try and figure out. Hope this helps.

大多数情况下,jenkins实例中的每个页面都将具有REST API链接.请单击它以查看其余api网址以及该网址的输出.

Mostly for every page in the jenkins instance, you will be having REST API link. Please click on it to see the rest api url and its output for that url.

这篇关于Jenkins Java:获取开始构建的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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