Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60498

Duplicate Ids for ConfigFiles when using CasC

    Details

    • Similar Issues:

      Description

      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:

       

      grep -B 1 "<id>" org.jenkinsci.plugins.configfiles.GlobalConfigFiles.xml
          <org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig>
            <id>GlobalSettingsNexus</id>
      --
          <org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig>
            <id>GlobalSettingsNexus</id>
      --
          <org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig>
            <id>GlobalSettingsNexus</id>
      

      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.:

      head -4 org.jenkinsci.plugins.configfiles.GlobalConfigFiles.xml
      <?xml version='1.1' encoding='UTF-8'?>
      <org.jenkinsci.plugins.configfiles.GlobalConfigFiles plugin="config-file-provider@3.6.2">
        <configs class="set">
          <org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig>
      

      which should be (this is from a jenkins configured using the UI):

      head -4 ../jenkins-2.176.2/org.jenkinsci.plugins.configfiles.GlobalConfigFiles.xml
      <?xml version='1.1' encoding='UTF-8'?>
      <org.jenkinsci.plugins.configfiles.GlobalConfigFiles plugin="config-file-provider@3.5">
        <configs class="sorted-set">
          <comparator class="org.jenkinsci.plugins.configfiles.GlobalConfigFiles$1"/>
      

      We have a YAML file with our maven and node settings which looks like this:

      unclassified: 
        globalConfigFiles: 
          configs: 
            - globalMavenSettings: 
                comment: "global settings"
                content: |-
                  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
                   ...
      

      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
       

       

        Attachments

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              domi Dominik Bartholdi
              Reporter:
              sebastian_e_m Sebastian Mahr
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: