Jenkins 获取中止构建的用户

dja*_*jan 5 jenkins jenkins-pipeline

当用户中止构建时,有没有办法获取用户名?最好使用詹金斯管道代码。

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

Aborted by <username>
Run Code Online (Sandbox Code Playgroud)

所以我希望它在短时间内作为变量存储。

用例:稍后用于通过电子邮件或其他消息传递方式通知用户本身或其他用户的用户名。

tof*_*der 7

如果作业中止,似乎 InterruptedBuildAction 对象被插入到构建操作列表中。此对象可用于检索中止构建的用户。我在 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
}
Run Code Online (Sandbox Code Playgroud)


Ger*_*ica 2

不幸的是,目前似乎没有其他解决方案,只能调整 Jenkin 的代码本身和解决方法。

\n\n

构建后操作\xe2\x86\x92可编辑电子邮件通知\xe2\x86\x92触发器\xe2\x86\x92添加触发器\xe2\x86\x92已中止\xe2\x86\x92发送到\xe2\x86\x92添加\xe2\x86\x92请求者\xe2\x86\x92\xe2\x86\x92 ... Jenkins 邮件插件

\n\n
\n

向发起构建的用户发送电子邮件。

\n
\n\n

没有要添加的Aborter

\n\n

http://<jenkins>/job/<project name>/lastBuild/api/xml显示:

\n\n
...\n<result>ABORTED</result>\n...\n
Run Code Online (Sandbox Code Playgroud)\n\n

但也没有任何信息是谁中止了构建。

\n\n

解决方法可能是在构建后任务curl http://<jenkins>/job/<project name>/<build #>脚本中并for .grep<p>Aborted by user username</p>

\n