Extension methods do not work in Pipeline

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

XMLWordPrintable

      Trying to make use of extension methods but haven't managed to get it work.
      In example, outside of pipeline this fails:

      String.metaClass.toTitleCase = { -> toLowerCase().tokenize(" ")*.capitalize().join(" ") }

      returning "spread not yet supported", but below code in post stage of pipeline (making html email) works fine:

      entry.User = "${fields[1]}".replace(".", " ").trim().tokenize(" ")*.capitalize().join(" ")

      which may mean that spread actually works.
       
      replacing extension method with: 

      String.metaClass.toTitleCase = {
        def words = phrase.toLowerCase().tokenize(" ")
        words.collect{ -> capitalize() }
        String result = words.join(" ")
        return result;
      }

      gives other error: "No signature of method: java.lang.String.toTitleCase() is applicable for argument types: () values: []"

      I think there is some error around handling extension methods here.

      abayer could you check if its not like the bug https://issues.jenkins-ci.org/browse/JENKINS-47193 where classes outside pipeline were not being parsed? 

       

       
       

            Assignee:
            Unassigned
            Reporter:
            Jakub Pawlinski
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: