当用户中止构建时,是否可以获取用户名?
最好使用jenkins管道代码。
当用户中止构建时,它记录:
Aborted by <username>
因此,我希望将其作为变量存储一小段时间。
用例:用户名以后将用于通过电子邮件或其他消息传递方式通知用户本身或其他用户。
最佳答案
如果作业中止,似乎将InterruptedBuildAction对象插入到构建 Action 列表中。该对象可用于检索中止构建的用户。我在Jenkinsfile中使用以下功能:
@NonCPS
def getAbortUser()
{
def causee = ''
def actions = currentBuild.getRawBuild().getActions(jenkins.model.InterruptedBuildAction)
for (action in actions) {
def causes = action.getCauses()
// on cancellation, report who cancelled the build
for (cause in causes) {
causee = cause.getUser().getDisplayName()
cause = null
}
causes = null
action = null
}
actions = null
return causee
}
关于Jenkins获得了中止构建的用户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44890354/