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

Cannot pass Groovy method references as parameters for DSL objects

XMLWordPrintable

      It is not possible to pass Groovy method references as parameters to other methods if the method reference points to a DSL object. The code below demonstrates that the method reference works fine with the "println" method available to all Groovy objects, but fails when the reference points to "steps.echo", where steps is the DSL object available in all Jenkinsfiles.

      foo(this.&println)
      foo(steps.&echo)
      
      def foo(arg) {
          arg.call("hello")
      }
      

      fails with the following:

      [Pipeline] echo
      hello
      [Pipeline] End of Pipeline
      [BFA] Scanning build for known causes...
      [BFA] No failure causes found
      [BFA] Done. 0s
      hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.workflow.cps.DSL.echo() is applicable for argument types: (java.lang.String) values: [hello]
      

            Unassigned Unassigned
            boon Joe Harte
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: