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

JCasC export doesn't work with Custom Tools installed and configured

      When the Custom Tools plugin is installed and a Custom Tool is configured and JCasc 'View Configuration' button is clicked and the following error results in the Casc output:

      ```customTool:
      installations: |-
      FAILED TO EXPORT
      com.cloudbees.jenkins.plugins.customtools.CustomTool$DescriptorImpl#installations: java.lang.IllegalArgumentException: argument type mismatch
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)```

       

      I attempted this with the following versions:

      Configuration as Code Plugin version 1.32
      Configuration as Code Support Plugin version 1.19
      Custom Tools version .6
      Jenkins version 2.190.1

       

          [JENKINS-60045] JCasC export doesn't work with Custom Tools installed and configured

          FWIW, the syntax for configuring custom tools via JCasC appears to be like this:

          tool:
            customTool:
              installations:
              - name: "DocFx"
                home: ""
                properties:
                - installSource:
                    installers:
                    - zip:
                        label: "windows"
                        url: "https://github.com/dotnet/docfx/releases/download/v2.39.2/docfx.zip"
          

          Kalle Niemitalo added a comment - FWIW, the syntax for configuring custom tools via JCasC appears to be like this: tool: customTool: installations: - name: "DocFx" home: "" properties: - installSource: installers: - zip: label: "windows" url: "https://github.com/dotnet/docfx/releases/download/v2.39.2/docfx.zip"

          Kalle Niemitalo added a comment - - edited

          A longer stack trace from Jenkins 2.190.3, Custom Tools Plugin 0.7, Configuration as Code Plugin 1.34, Configuration as Code Support not installed:

          FAILED TO EXPORT
          com.cloudbees.jenkins.plugins.customtools.CustomTool$DescriptorImpl#installations: java.lang.IllegalArgumentException: argument type mismatch
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.describe(DataBoundConfigurator.java:299)
            at io.jenkins.plugins.casc.Attribute._describe(Attribute.java:264)
            at io.jenkins.plugins.casc.Attribute.describe(Attribute.java:239)
            at io.jenkins.plugins.casc.Configurator.describe(Configurator.java:162)
            at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator.describe(GlobalConfigurationCategoryConfigurator.java:106)
            at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator.lambda$describe$3(GlobalConfigurationCategoryConfigurator.java:99)
            at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator$$Lambda$286.0000000000000000.accept(Unknown Source)
            at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
            at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
            at java.util.Iterator.forEachRemaining(Iterator.java:116)
            at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
            at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:497)
            at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:487)
            at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
            at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
            at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:241)
            at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485)
            at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator.describe(GlobalConfigurationCategoryConfigurator.java:99)
            at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator.describe(GlobalConfigurationCategoryConfigurator.java:30)
          

          Kalle Niemitalo added a comment - - edited A longer stack trace from Jenkins 2.190.3, Custom Tools Plugin 0.7, Configuration as Code Plugin 1.34, Configuration as Code Support not installed: FAILED TO EXPORT com.cloudbees.jenkins.plugins.customtools.CustomTool$DescriptorImpl#installations: java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.describe(DataBoundConfigurator.java:299) at io.jenkins.plugins.casc.Attribute._describe(Attribute.java:264) at io.jenkins.plugins.casc.Attribute.describe(Attribute.java:239) at io.jenkins.plugins.casc.Configurator.describe(Configurator.java:162) at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator.describe(GlobalConfigurationCategoryConfigurator.java:106) at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator.lambda$describe$3(GlobalConfigurationCategoryConfigurator.java:99) at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator$$Lambda$286.0000000000000000.accept(Unknown Source) at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) at java.util.Iterator.forEachRemaining(Iterator.java:116) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:497) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:487) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:241) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485) at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator.describe(GlobalConfigurationCategoryConfigurator.java:99) at io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator.describe(GlobalConfigurationCategoryConfigurator.java:30)

          I wonder if the error is triggered by com.cloudbees.jenkins.plugins.customtools.CustomTool$DescriptorImpl overriding setInstallations with a concrete type but not getInstallations.  Might be related to this comment in io.jenkins.plugins.casc.BaseConfigurator#describe:

                  // Resolve the methods and merging overrides to more concretized signatures
                  // because the methods can to have been overridden with concretized type
                  // TODO: Overloaded setters with different types can corrupt this logic
          

          Kalle Niemitalo added a comment - I wonder if the error is triggered by com.cloudbees.jenkins.plugins.customtools.CustomTool$DescriptorImpl overriding setInstallations with a concrete type but not getInstallations .  Might be related to this comment in io.jenkins.plugins.casc.BaseConfigurator#describe : // Resolve the methods and merging overrides to more concretized signatures // because the methods can to have been overridden with concretized type // TODO: Overloaded setters with different types can corrupt this logic

          Kalle Niemitalo added a comment - - edited

          The exception was thrown during the newInstance call at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.describe(DataBoundConfigurator.java:299):

          T ref = (T) constructor.newInstance(args);
          

          The type being constructed should be CustomTool, and I think it is. If the type had been CustomTool[] or ToolInstallation[] or ToolInstallation, then DataBoundConfigurator.getDataBoundConstructor would have returned null, and DefaultConfiguratorRegistry.internalLookup would not have created an instance of DataBoundConfigurator.

          So, it seems to be a matter of incorrect arguments being generated for the CustomTool constructor.

          Perhaps the error is triggered by the @CheckForNull LabelSpecifics[] labelSpecifics parameter of that constructor. If CustomTool.getLabelSpecifics returns an array, then the type of this array does not implement java.util.Collection, so DataBoundConfiguration.describe assigns args[i] = Collections.singletonList(converted), which is not acceptable to the constructor.

          If this theory is correct, then the error could be fixed either by changing CustomTool to use a collection type instead of the array type, or by changing DataBoundConfigurator to check for array types as well. I cannot currently test these changes myself.

          Kalle Niemitalo added a comment - - edited The exception was thrown during the newInstance call at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.describe( DataBoundConfigurator.java:299 ): T ref = (T) constructor.newInstance(args); The type being constructed should be CustomTool , and I think it is. If the type had been CustomTool[] or ToolInstallation[] or ToolInstallation , then DataBoundConfigurator.getDataBoundConstructor would have returned null, and DefaultConfiguratorRegistry.internalLookup would not have created an instance of DataBoundConfigurator . So, it seems to be a matter of incorrect arguments being generated for the CustomTool constructor . Perhaps the error is triggered by the @CheckForNull LabelSpecifics[] labelSpecifics parameter of that constructor. If CustomTool.getLabelSpecifics returns an array, then the type of this array does not implement java.util.Collection , so DataBoundConfiguration.describe assigns args [i] = Collections.singletonList(converted) , which is not acceptable to the constructor. If this theory is correct, then the error could be fixed either by changing CustomTool to use a collection type instead of the array type, or by changing DataBoundConfigurator to check for array types as well. I cannot currently test these changes myself.

          Fixed in configuration-as-code-plugin 1.35 with <https://github.com/jenkinsci/configuration-as-code-plugin/pull/1234/>.

          Kalle Niemitalo added a comment - Fixed in configuration-as-code-plugin 1.35 with < https://github.com/jenkinsci/configuration-as-code-plugin/pull/1234/ >.

            ewel Ewelina Wilkosz
            tisaroo55 TJ Rue
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: