如何在工作流中获得$ CAUSE [英] how to get $CAUSE in workflow

查看:288
本文介绍了如何在工作流中获得$ CAUSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins有一个$ CAUSE变量可用于自由式构建作业.

Jenkins has a $CAUSE variable available to freestyle build jobs.

如何在工作流程中访问此内容或类似内容?

How can I access this or something similar in workflow?

我的团队在现有临时构建的电子邮件输出中使用了它.我们希望在基于工作流的新作业中继续这样做.

My team makes use of it in email output of existing ad-hoc builds. We'd like to continue the same in new workflow based jobs.

推荐答案

似乎Workflow版本没有注入此变量. 但是,您可以使用

It looks like Workflow builds don't have this variable injected. However you can retrieve the required info from currentBuild.rawBuild object using hudson.model.Run.getCause() or hudson.model.Run.getCauses() method.

示例:

工作流程脚本:

println "CAUSE ${currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause).properties}"

结果如下:

Running: Print Message
CAUSE [userName:John Smith, userId:jsmith, class:class hudson.model.Cause$UserIdCause, shortDescription:Started by user John Smith]

其他原因子类型可以在 javadoc .

Other Cause subtypes can be found in the javadoc.

还有一个很好的 get-build-cause 示例这是基于jenkins 管道示例存储库中的答案.

There is also a good get-build-cause example which is based on this answer in the jenkins Pipeline Examples repository.

这篇关于如何在工作流中获得$ CAUSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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