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

Add Whitelisted method to get the trigger cause

    XMLWordPrintable

Details

    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

            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?

            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?

            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

            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 dnusbaum can you please confirm? Thanks
            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.

            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 .
            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.

            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 .
            filipe_pelica Filipe Pelica added a comment -

            Thank you very much dnusbaum! Everything is now clear.

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

            People

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

              Dates

                Created:
                Updated:
                Resolved: