如何在工作流程中获得 $CAUSE [英] how to get $CAUSE in workflow
问题描述
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.
推荐答案
看起来工作流构建没有注入这个变量.但是,您可以使用 hudson.model.Run.getCause() 或 hudson.model.Run.getCauses() 方法.
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 Pipeline Examples 存储库中的这个答案.
There is also a good get-build-cause example which is based on this answer in the jenkins Pipeline Examples repository.
这篇关于如何在工作流程中获得 $CAUSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!