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

Varargs mishandled in Groovy CPS

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • pipeline
    • Jenkins ver. 1.606
      Workflow 1.5

      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.

            kohsuke Kohsuke Kawaguchi
            tomjdalton Thomas Dalton
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: