Consider the following script:
node { fn("This should only be one string") } def fn (String... strs) { echo "${strs.size()}" }
This results in the following output:
Running: Allocate node : Body : Start Running: Print Message 30 Running: Allocate node : Body : End Running: Allocate node : End Running: End of Workflow Finished: SUCCESS
Under a groovy console the result is as we'd expect, there is one String in the array of Strings.
def fn (String... strs) { println "${strs.size()}" } fn("This should only be one string") return
Result:
1
I'm guessing this is just a bug?
In the meantime is there a workaround? I'd like a function to handle an array of strings, and need to loop through the Strings, not individual characters.
- is blocking
-
JENKINS-25979 Finish Groovy CPS coverage
-
- Open
-
[JENKINS-27893] Varargs mishandled in Groovy CPS
Labels | Original: jenkins workflow | New: groovy |
Assignee | Original: Jesse Glick [ jglick ] | New: Kohsuke Kawaguchi [ kohsuke ] |
Priority | Original: Minor [ 4 ] | New: Major [ 3 ] |
Summary | Original: String arrays, or variable args passed to functions don't seem to work | New: Varargs mishandled in Groovy CPS |
Link | New: This issue is blocking JENKINS-25979 [ JENKINS-25979 ] |
Resolution | New: Fixed [ 1 ] | |
Status | Original: Open [ 1 ] | New: Resolved [ 5 ] |
Workflow | Original: JNJira [ 162486 ] | New: JNJira + In-Review [ 196963 ] |
Component/s | New: pipeline-general [ 21692 ] |
You may be the first to try to use varargs in a Groovy CPS-transformed script. Disambiguating varargs calls is complicated enough in Java, and argument handling is an order of magnitude more complicated in Groovy, so I am not that surprised it does not work. The following does work: