Jenkins获得了中止构建的用户 [英] Jenkins get user who aborted a build

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

问题描述

当用户中止构建时,是否可以获取用户名? 最好使用jenkins管道代码.

Is there a way to get the username when a build is aborted by a user? Preferably using jenkins pipeline code.

当用户中止构建时,它会记录:

When a build is aborted by a user, it logs:

Aborted by <username>

所以我希望将其作为变量存储一小段时间.

so I hope it is stored as a variable for a brief period.

用例:用户名,以后将用于通过电子邮件或其他消息传递方式通知用户本身或其他用户.

Use case: username to be later used to inform the user itself or other users via email or other means of messaging.

推荐答案

如果作业中止,似乎InterruptedBuildAction对象已插入到构建动作列表中.该对象可用于检索中止构建的用户.我在Jenkinsfile中使用以下功能:

It seems that a InterruptedBuildAction object is inserted in to the list of build action if a job is aborted. This object can be used to retrieve the user that aborted the build. I use the following function in my 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获得了中止构建的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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