Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55758

Add Whitelisted method to get the trigger cause

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            filipe_pelica Filipe Pelica added a comment -

            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?

            Show
            filipe_pelica Filipe Pelica added a comment - 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?
            Hide
            batmat Baptiste Mathus added a comment -

            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

            Devin Nusbaum can you please confirm? Thanks

            Show
            batmat Baptiste Mathus added a comment - 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 Devin Nusbaum can you please confirm? Thanks
            Hide
            dnusbaum Devin Nusbaum added a comment -

            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.

            Show
            dnusbaum Devin Nusbaum added a comment - 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 .
            Hide
            dnusbaum Devin Nusbaum added a comment - - edited

            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.

            Show
            dnusbaum Devin Nusbaum added a comment - - edited 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 .
            Hide
            filipe_pelica Filipe Pelica added a comment -

            Thank you very much Devin Nusbaum! Everything is now clear.

            Show
            filipe_pelica Filipe Pelica added a comment - Thank you very much Devin Nusbaum ! Everything is now clear.

              People

              • Assignee:
                rodrigc Craig Rodrigues
                Reporter:
                filipe_pelica Filipe Pelica
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: