我如何发现Jenkins构建的其他原因? [英] How do I discover the additional causes of my Jenkins build?
问题描述
当试图使用groovy查询构建时,我称之为
$ p $ my code myBuild.getCauses()
我可以在Jenkins的界面(构建屏幕)中看到此构建有两个原因,UserIdCause和UpstreamCause。然而,当我用上面的groovy询问相同的构建时,我只返回一个单一的原因,即UserIdCause。必须有一些从构建中获取UpstreamCause的方法,或者它不会出现在用户界面中。
我使用Build Pipeline插件手动触发
这里是工作的groovy代码(我在jenkins脚本控制台中试过)使用 build.getAction
job = hudson.model.Hudson.instance.getItem(demo-job )
build = job.getLastBuild()
//首先获取动作
def action = build.getAction(hudson.model.CauseAction.class)
/ /获得原因列表$(原因在action.getCauses()){
println cause.getShortDescription()
}
//另一种方法直接查找特定的UpsteamCause
cause = action.findCause(hudson.model.Cause.UpstreamCause.class)
println cause.getUpstreamRun()
请参阅
- 请参阅build-pipeline-plugin如何在代码 BuildPipelineView.java
- 请参阅 hudson.model.Cause API
When attempting to query a build using groovy, I call
myBuild.getCauses()
I can see in the interface of Jenkins (the build screen) that this build has two causes, a UserIdCause, and an UpstreamCause. However, when I interrogate the same build with the groovy above, I only get a single cause back, which is the UserIdCause. There must be some method of getting the UpstreamCause from the build, or it wouldn't be present in the user interface.
I am using the Build Pipeline plugin to manually trigger the builds.
Here is the working groovy code (I tried in jenkins script console) to use build.getAction
job = hudson.model.Hudson.instance.getItem("demo-job")
build = job.getLastBuild()
// get action first
def action = build.getAction(hudson.model.CauseAction.class)
// get the list of causes
for (cause in action.getCauses()) {
println cause.getShortDescription()
}
// another way to find specific UpsteamCause directly
cause = action.findCause(hudson.model.Cause.UpstreamCause.class)
println cause.getUpstreamRun()
See reference
- see build-pipeline-plugin how to add cause in code BuildPipelineView.java
- see the hudson.model.Cause API
这篇关于我如何发现Jenkins构建的其他原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!