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

Appending to list doesn't work with some classes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • Jenkins 2.107.2
      Pipeline 2.5
      Pipeline-groovy 2.49

      It is not possible to add multiple objects to a list and join them to a string.

      Only the first added object will be in the output string.

      This code snippert works perfectly fine in normal groovy, but not with jenkins groovy :-/

      class TemplateParameter implements Serializable {
          final String parameter
          final String value

          TemplateParameter(String parameter, String value) {
              assert parameter
              this.parameter = parameter.toUpperCase()
              assert value
              this.value=value
          }

          String toString() {
              "-p=$parameter=$value"
          }
      }

      node('master') {
          def branch = 'foobar'
          def revision = '1337'
          
          List<TemplateParameter> result = []
          result += new TemplateParameter('rev', revision)
          result += new TemplateParameter('branch', branch)
          println "[DEBUG] Template Parameters size: ${result.size()}"
          println "[DEBUG] Template Parameters: ${result.join(' ')}"
      }

      Output:

      [Pipeline] {
      [Pipeline] echo
      [DEBUG] Template Parameters size: 2
      [Pipeline] echo
      [DEBUG] Template Parameters: -p=REV=1337
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline

      Expected:

      [DEBUG] Template Parameters size: 2
      [DEBUG] Template Parameters: -p=REV=1337 -p=BRANCH=foobar

       

       

            Unassigned Unassigned
            xaseron Michael Werner
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: