如何在工作流中获得$ 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.
推荐答案
似乎Workflow版本没有注入此变量. 但是,您可以使用 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 管道示例存储库中的答案.
There is also a good get-build-cause example which is based on this answer in the jenkins Pipeline Examples repository.
这篇关于如何在工作流中获得$ CAUSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!