Cannot pass Groovy method references as parameters for DSL objects

This issue is archived. You can view it, but you can't modify it. Learn more

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]
      

            Assignee:
            Unassigned
            Reporter:
            Joe Harte
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: