繁体   English   中英

Jenkins Java:如何获取在jenkins中触发构建的用户的用户标识

[英]Jenkins Java: How to get the userid of the user who triggered the build in jenkins

有没有办法找出谁使用Java在jenkins中开始构建。 我了解以下是确定谁开始构建的方法

import hudson.model.*  
import jenkins.security.*

def userBuild
for(hudson.model.Cause cause : build.causes) {
    userBuild = cause.getUserName()
}
println "Build Started by: "+userBuild

同样,有人可以让我知道是否有类似的工作方法可以弄清楚谁发起了詹金斯构建吗?

Ther是一个插件,可将信息注入构建变量中。 https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin

 BUILD_USER – full name of user started build, BUILD_USER_FIRST_NAME – first name of user started build, BUILD_USER_LAST_NAME – last name of user started build, BUILD_USER_ID – id of user started build. 

也许这是您的选择。

能够自己解决。 在buildCaption.jelly中添加了以下更改,以便只有启动构建的用户才能中止构建。 请注意,此更改仅反映在构建的控制台输出中,但是在其他地方(例如jenkins登陆页面和作业主页)会显示中止按钮,因此必须做出相应的更改

<j:forEach var="cause" items="${it.causes}">
    <j:if test="${cause.userName == it.currentlyLoggedInUser}">
      <l:stopButton href="stop" alt="[${%cancel}]"/>
    </j:if>
</j:forEach>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM