在 Jenkins 中,构建如何知道谁请求了它们? [英] In Jenkins, how do builds know who requested them?

查看:27
本文介绍了在 Jenkins 中,构建如何知道谁请求了它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将构建请求者的用户名传递给实际执行工作的脚本.查看特定构建的控制台输出,第一行始终是由用户 foo 启动".所以詹金斯显然在跟踪谁触发了构建.所以应该可以将这些信息传递给工作.问题是,如何?

I need to pass the username of the requester of a build down to the script that is actually doing the work. Looking at the console output for a particular build, the first line is always "Started by user foo," so Jenkins is clearly keeping track of who triggered the build. So it should be possible to pass that information down to the job. The question is, how?

推荐答案

用户名未放在易于获取的环境变量中,但您可以使用 xml(或 json 或 python)api - 一旦开始构建,http://[jenkins-server]/job/[job-name]/[build-number]/api/xml 填充了详细信息:

The username isn't put in an easy-to-fetch environment variable, but you can get it using the xml (or json or python) api - as soon as you start a build, http://[jenkins-server]/job/[job-name]/[build-number]/api/xml is populated with details:

<freeStyleBuild>
    <action>
        <cause>
            <shortDescription>Started by user foobar</shortDescription>
            <userName>foobar</userName>
        </cause>
    </action>
    <building>true</building>
    [...]

这篇关于在 Jenkins 中,构建如何知道谁请求了它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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