-
Bug
-
Resolution: Unresolved
-
Minor
-
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?
[JENKINS-47450] Extension methods do not work in Pipeline
Component/s | New: workflow-cps-plugin [ 21713 ] | |
Component/s | Original: pipeline-utility-steps-plugin [ 21135 ] |
Assignee | Original: rsandell [ rsandell ] |
Summary | Original: Extension methods does not work in declarative pipeline | New: Extension methods do not work in Pipeline |
It looks like spread not yet supported happens when method is not @NonCPS, with this flag it works fine.
Unfortunately it looks like @NonCPS cannot be used with extension methods.