My Jenkins is affected by a known Jenkins bug where it will trigger jobs that have an SCM poll set if a change to the shared library happens. I can't have this, so I thought I would get the trigger info from inside the job and if the URL was from the library repo I would abort the build. This has proven to be extremely difficult to do.
This doesn't work...
println ("Cause: " + currentBuild.causes[0])
or
print currentBuild.rawBuild.getCause(hudson.triggers.SCMTrigger$SCMTriggerCause)
or
def causes = currentBuild.rawBuild.getCauses()
for (cause in causes) {
print cause
}
The first example barfs
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified field org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper causes
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.unclassifiedField(SandboxInterceptor.java:397)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:381)
but doesn't allow me to whitelist it on the script security page.
The last 2 print thing hudson.triggers.SCMTrigger$SCMTriggerCause@3 but it seems the only thing I can do is call getShortDescription() and it prints Started by an SCM change.
If you know how to print more information about an SCM trigger such as the URL please share =).