Why doesn't the default attribute for number fields work for Jenkins jelly configurations?

576 views Asked by At

I'm working on a Jenkins plugin where we make a call out to a remote service using Spring's RestTemplate. To configure the timeout values, I'm setting up some fields in the global configuration using the global.jelly file for Jenkins plugins using a number field as shown here:

<f:entry title="Read Timeout" field="readTimeout" description="Read timeout in ms.">
    <f:number default="3000"/>
</f:entry>

Now, this works to save the values and retrieve the values no problem, so it looks like everything is setup correctly for my BuildStepDescriptor. However, when I first install the update to a Jenkins instance, instead of getting 3000 in the field by default as I would expect, instead I am getting 0. This is the same for all the fields that I'm using.

Given that the Jelly tag reference library says this attribute should be the default value, why do I keep seeing 0 when I first install the plugin?

Is there some more Java code that needs to be added to my plugin to tie the default in Jelly back to the global configuration?

1

There are 1 answers

0
KeepCalmAndCarryOn On

I would think that when Jenkins starts, it goes to get the plugin configuration XML and fails to find a value and sets it to a default of 0.

I have got round this in the past by setting a default in the descriptor (in groovy) then this value will be saved into the global config the first time in and also be available if the user never visits the config page.

@Extension
static class DescriptorImpl extends AxisDescriptor {
    final String displayName = 'Selenium Capability Axis'

    String server = 'http://localhost:4444'

    Boolean sauceLabs = false
    String sauceLabsName
    Secret sauceLabsPwd
    String sauceLabsAPIURL = 
           'http://saucelabs.com/rest/v1/info/platforms/webdriver'
    String sauceLabsURL = 'http://ondemand.saucelabs.com:80'

from here