Determine the URL for a SCM trigger from inside the build 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 (&quot;Cause: &quot; + 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 =).
Some bad news and some good news :)

Bad news:

not a bug. this is a feature (default behaviour)

I don't understand why this bug is still open, either regression, or miscommunication.

Good news:

During setup of Global Shared Libraries jenkins allows to mark whether you should trigger user jobs upon changes in the library.
And, you can also mark this during library usage in the job's groovy.

Please refer to:


https://issues.jenkins-ci.org/browse/JENKINS-41497
https://stackoverflow.com/questions/46819344/jenkins-shared-groovy-library-git-merge-triggering-jobs