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

A List passed to a function is received as a String

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • pipeline
    • 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.

            jglick Jesse Glick
            dmbirch Dean Birch
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: