Status: Resolved (View Workflow)
As pointed out in the pipeline examples (https://jenkins.io/doc/pipeline/examples/#get-build-cause), there is no native way to retrieve the build trigger cause and therefore it is suggested to get it by using the `currentBuild.rawBuild` variable:
// Get all Causes for the current build def causes = currentBuild.rawBuild.getCauses()
However the SCM scripts are not permitted to use the getRawBuild method, as shown bellow:
Error getting build cause: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
Can you please consider to change the referred method to whitelisted method.
JENKINS-54227 Safely expose the Cause(s) associated with the current build
JENKINS-41272 Pipeline "currentBuild" should expose build causes
- links to
Most probably the wrong plugin component, build-flow-plugin is deprecated.
Not 100% which one in the Pipeline ecosystem, apparently workflow-support given https://github.com/jenkinsci/workflow-support-plugin/blob/c019079f526f627665c812fe86dd72419075df62/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java#L83
dnusbaum can you please confirm? Thanks
filipe_pelica You can use currentBuild#getBuildCauses and the overload that takes a fully qualified class name from the sandbox. These methods were added in workflow-support 2.22, see the changelog.
I will try to file a PR to update https://jenkins.io/doc/pipeline/examples/#get-build-cause to use the new methods sometime in the next week or so. EDIT: I filed https://github.com/jenkinsci/pipeline-examples/pull/95.
Thank you very much dnusbaum! Everything is now clear.
I just realized that this method is intentionally not whitelisted, as described in the Javadoc: https://javadoc.jenkins.io/plugin/workflow-support/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.html#getRawBuild--
According to this, can you please provide any other way to access the build trigger cause compatible with SCM scripts?