How to add list of configurable elements to a Jenkins plugin configuration page?

494 views
Skip to first unread message

Tomas Bjerre

unread,
Nov 15, 2015, 3:51:35 PM11/15/15
to Jenkins Developers
How to add list of configurable elements to a Jenkins plugin configuration page?

I have a list of configurable items. It should be able to grow dynamically and each item has 3 fields. There is initially one row, if that is populated I want to add a new empty row.

I have 2 Java files to store the config.
...
public class MainConfigRecorder {
 List<CustomConfig> customConfigs;
...
And the customConfig
...
public class CustomConfig {
 private String name;
 private String pattern;
 private String link;
 ...
 public String getLink()
 ...
 public void setLink(String link)
 ...
...

In the config.jelly I loop through the customConfigs:

...
  <j:forEach var="customConfig" items="${config.customConfigs}" indexVar="i">
    <f:block>
    <table cellspacing="5">
      <tr>
        <td width="200">
          <f:textbox name="customConfig[${i}].name" value="${customConfig.name}" />
...

Problem is when the config is saved! I cannot deserialize it to the Java objects.

I can see this when I inspect the HTML code in browser:

<input name="customIssues[0].name" type="text" class="setting-input   " value="">

When the form i ssubmitted and I debug:

public final class GitReleasenotesDescriptor extends BuildStepDescriptor<Publisher> {
...
 @Override
 public Publisher newInstance(StaplerRequest req, JSONObject formData)

I can see this in formData:

{"fromType":"fromFirstCommit","fromReference":"","toType":"toMaster","toRefeference":"","name":"name","pattern":"pattern","link":"link","stapler-class":"org.jenkinsci.plugins.grl.GitReleasenotesRecorder","kind":"org.jenkinsci.plugins.grl.GitReleasenotesRecorder"}

I did not expect:
..."name":"name","pattern":"pattern","link":"link"...
I was expecting:
..."customIssues": [{ "name":"name","pattern":"pattern","link":"link"}]...


Any suggestions?

Tomas Bjerre

unread,
Nov 15, 2015, 5:03:22 PM11/15/15
to Jenkins Developers

It seems I should use repeatable tag here (https://jenkins-ci.org/maven-site/jenkins-core/jelly-taglib-ref.html#form:repeatable) but I'm now getting a Javascript error. Perhaps a Jenkins-bug? See the ip variable is undefined here.

<f:repeatable var="customIssue" field="customIssues" items="${config.customIssues}">
    <table>
    <tr>
      <th align="left" width="200">
      <f:entry field="name">
        <f:textbox value="${customIssue.name}" default="" />
      </f:entry>
      </th>
    </tr>
    </table>
  </f:repeatable>
Reply all
Reply to author
Forward
0 new messages