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

Extension methods do not work in Pipeline

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None

      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? 

       

       
       

            Unassigned Unassigned
            quas Jakub Pawlinski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: