Search code examples
jenkinsjenkins-pluginsjelly

Jenkins plugin drop-down menu


Somehow I am not able to store values from drop-down menus, that I added to the jelly.xml for my Jenkins plugin. Text fields work just fine on the other hand

jelly:

<f:entry title="Catch+ Version" field="selection">
  <f:select/>
</f:entry>

I added nothing to the databound constructor. Maybe this is already the problem. I didn't know how to add it, since it's not a string but a list?!

So I only added the doFillSelectionItems function, which works as it should.

public ListBoxModel doFillSelectionItems()
{
    return new ListBoxModel(new Option("1.13", "1.13"),
                    new Option("1.14", "1.14"),
                    new Option("1.15", "1.15"));
}

and also to the configure method before save():

catchVersion = formData.getString("selection");

I can change between the three Options and the value is stored, no doubt. I can run the build several times and it's using the selected value, BUT: if I go to configure project again, always the first option is selected, no matter what I had chosen before. How can I make the stored value appear here?


Solution

  • There is a third parameter to the Option constructor which defines the current selection. You can also pass the current value in

    public ListBoxModel doFillSelectionItems(@QueryParameter String selection) {
        return new ListBoxModel(new Option("1.13", "1.13", selection.matches("1.13") ),
                        new Option("1.14", "1.14", selection.matches("1.14") ),
                        new Option("1.15", "1.15", selection.matches("1.15") ));
    }
    

    Adapted from here but this is an example using the global config