简体   繁体   中英

Jenkins Groovy: What triggered job

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

I want to get list of jobs triggered automatically. Now i have list of all jobs.

You can get the Cause which triggered the build.

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)
}

This class has many subclasses, which you can you to determine what triggered the build:

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

println currentBuild.getBuildCauses().shortDescription[0]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM