In our organization, we configure our jenkins instances using configuration-as-code for initial provisioning, but allow changes to the configuration over time.
When providing a set of config files like that and modifying a configuration like maven settings, the edited object does not get modified, instead a new config file object with the same id is created when saving:
When jobs request a config file by id, which instance they get is undefined.After some investigation, the collection of ConfigFile objects gets saved as a standard java.util.set instead of the TreeSet defined by the class.:
which should be (this is from a jenkins configured using the UI):
We have a YAML file with our maven and node settings which looks like this:
The CasC configurator calls GlobalConfigFiles.setConfigs() with a normal java.util.Set, overrding the internal treeset and leading to the behavior described above.
A setter should not change the datastructure if you rely on the sorting behavior
To fix: The setter should internally convert its Collection parameter to a TreeSet with the correct Comparator