Jenkins Groovy:什么引发了工作

时间:2017-12-05 10:49:24

标签: jenkins groovy

Jenkins.instance.getAllItems(AbstractProject.class).each {it ->
println it.fullName
println it.getLastBuild().getTime()
}

我想获得自动触发的作业列表。现在我列出了所有工作。

2 个答案:

答案 0 :(得分:0)

您可以获得触发构建的Cause

Jenkins.instance.getAllItems(AbstractProject.class).each {
  hudson.model.Cause cause = it.getLastBuild().getCause(hudson.model.Cause.class)
  println "Is triggered by user: " + (cause.class == hudson.model.Cause.UserIdCause.class)
}

此类有许多子类,您可以使用它们来确定触发构建的内容:

  

Cause.LegacyCodeCause,Cause.RemoteCause,Cause.UpstreamCause,   Cause.UpstreamCause.DeeplyNestedUpstreamCause,Cause.UserCause,   Cause.UserIdCause,SCMTrigger.SCMTriggerCause,   TimerTrigger.TimerTriggerCause

答案 1 :(得分:0)

println currentBuild.getBuildCauses().shortDescription[0]