-
Bug
-
Resolution: Duplicate
-
Minor
-
None
I have a list in one scope, then pass the same list to another function, where it gets received as a String.
def doSomething(def badList) { //this outputs 'foo' echo "This is my list now: " + badList.toString() } def createList() { return "foo,bar,baz".split(",") } node() { niceList = createList() //Prints [foo, bar, baz] as expected echo "Nice list is: " + niceList.toString() doSomething(niceList) }
The code above outputs the following:
... Running: Allocate node : Body : Start Running: Print Message Nice list is: [foo, bar, baz] Running: Print Message This is my list now: foo Running: Allocate node : Body : End Running: Allocate node : End Running: End of Workflow Finished: SUCCESS
I was wondering if this was just how groovy behaves, but it turns out it isn't. The following groovy code which is largely the same, except println replace echo, and node is omitted, outputs sensibly:
def doSomething(def badList) { println "This is my list now: " + badList.toString() } def createList() { return "foo,bar,baz".split(",") } //node() { niceList = createList() //Prints [foo, bar, baz] as expected println "Nice list is: " + niceList.toString() doSomething(niceList) //}
Output:
Nice list is: [foo, bar, baz] This is my list now: [foo, bar, baz]
Edit Workflow plugin(s) version: 1.10.1. Jenkins version: 1.652.3. I will see if problem persists when updating workflow version.
- duplicates
-
JENKINS-32062 Arrays may not be passed directly to methods
- Resolved