Default value for new properties in plugin configuration

18 views
Skip to first unread message

Marcin Zajączkowski

unread,
Apr 22, 2016, 5:06:16 PM4/22/16
to jenkin...@googlegroups.com
Hi,

In the plugin I would like to add new properties which should be set to
default values when upgrading from the older plugin versions.

I've read that it can be done in Jelly, but it only applies to the
situation when Jenkins configuration is saved. In my case after upgrade
values are deserialized from XML configuration which does not have those
values. The new integer field is set to 0 (no entry in XML) which is not
the best value for me. I tried to set default value in code, but it is
overridden when extension instance is created at Jenkins startup.

How can I set a default value to a new plugin configuration property to
be set when Jenkins is restarted after plugin upgrade?

Marcin

--
http://blog.solidsoft.info/ - Working code is not enough

Daniel Beck

unread,
Apr 22, 2016, 5:13:32 PM4/22/16
to jenkin...@googlegroups.com

> On 22.04.2016, at 23:06, Marcin Zajączkowski <msz...@wp.pl> wrote:
>
> How can I set a default value to a new plugin configuration property to
> be set when Jenkins is restarted after plugin upgrade?

To do this when your object is loaded, use readResolve, and if null, set whatever the new default is. Needs a nullable field to work, of course.

More here: https://wiki.jenkins-ci.org/display/JENKINS/Hint+on+retaining+backward+compatibility

Marcin Zajączkowski

unread,
Apr 22, 2016, 5:24:02 PM4/22/16
to jenkin...@googlegroups.com
That looks like something I need. Thanks Daniel.

Marcin

Reply all
Reply to author
Forward
0 new messages