There is not a great way in Jenkins databinding to handle String[]-valued properties. The general best practice is to make the property name as understood by Stapler (data binding) match the property name as understood by XStream (serial form), and for the type of both to be natural (a collection of some kind rather than a text blob). This makes for more consistent and predictable interaction with ways of defining job configuration other than the web UI. This tends to matter for the Workflow plugins (Describable objects instantiated as part of Step configuration from the Groovy DSL); Job DSL plugin; YAML Project plugin; etc.

      This commit gives an example of how you can make these align, even using the standard textarea.jelly control. The trick is to override Descriptor.newInstance. This is awkward though, and prevents you from using automatic databinding for other properties of the same class.

      It would be preferable to have a standard form control dedicated to representing a list of strings, probably rendered as a textarea (split on newlines and whitespace trimmed), though a series of textboxes with Add/Remove buttons is also an option. The representation created by buildFormTree should be a JSON array, which I believe Stapler already knows how to bind to Java arrays and/or lists; and FormChecker would ideally let you use a collection type in @QueryParameter for doCheck* methods as well. (Using a Set<String> as the property type is dubious, because duplicates will be silently deleted when the form is saved. Perhaps better to use a FormValidation warning to alert the user if duplicates are unwanted for the particular property.)

          [JENKINS-27901] Standard form control for string collections

          Code changed in jenkins
          User: Jesse Glick
          Path:
          basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java
          http://jenkins-ci.org/commit/workflow-plugin/df1825c211c5c6be0875c9d4c334c9f7aed3d8ba
          Log:
          JENKINS-27901 Noting.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java http://jenkins-ci.org/commit/workflow-plugin/df1825c211c5c6be0875c9d4c334c9f7aed3d8ba Log: JENKINS-27901 Noting.

          Dominik Bartholdi added a comment - - edited

          this would really be great!
          Now that more and more plugins try to integrate/support with the workflow plugin, we start to discover the very strange object structures generated (just to satisfy the form binding) - this would at least allow to simplify some of it.

          Dominik Bartholdi added a comment - - edited this would really be great! Now that more and more plugins try to integrate/support with the workflow plugin, we start to discover the very strange object structures generated (just to satisfy the form binding) - this would at least allow to simplify some of it.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java
          http://jenkins-ci.org/commit/workflow-basic-steps-plugin/2bffe36734ffdaba8cc85071b53c4d7d7bf7b509
          Log:
          JENKINS-27901 Noting.
          Originally-Committed-As: df1825c211c5c6be0875c9d4c334c9f7aed3d8ba

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java http://jenkins-ci.org/commit/workflow-basic-steps-plugin/2bffe36734ffdaba8cc85071b53c4d7d7bf7b509 Log: JENKINS-27901 Noting. Originally-Committed-As: df1825c211c5c6be0875c9d4c334c9f7aed3d8ba

          Jesse Glick added a comment -

          Noting Stapler PR 134 which touches on related code.

          Jesse Glick added a comment - Noting Stapler PR 134 which touches on related code.

          Pierson Yieh added a comment -

          Not sure if this is still being looked at, but would a repeatable field satisfy this requirement now https://github.com/jenkinsci/jenkins/blob/master/core/src/main/resources/lib/form/repeatable.jelly ? 

          We've used it for an in-house plugin that allowed users to configure a dynamically sized list of configurable items.

          Pierson Yieh added a comment - Not sure if this is still being looked at, but would a  repeatable field satisfy this requirement now https://github.com/jenkinsci/jenkins/blob/master/core/src/main/resources/lib/form/repeatable.jelly  ?  We've used it for an in-house plugin that allowed users to configure a dynamically sized list of configurable items.

          Jesse Glick added a comment -

          As noted in the issue description, you can patch together various approaches if you have to, but there is no standard control which handles all the databinding transparently.

          Jesse Glick added a comment - As noted in the issue description, you can patch together various approaches if you have to, but there is no standard control which handles all the databinding transparently.

            Unassigned Unassigned
            jglick Jesse Glick
            Votes:
            9 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: