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

JCasC: Branch discovery traits failure in config roundtrips (strategyId)

    Details

    • Similar Issues:

      Description

      When I export a configuration to JCasC, e.g. for a Pipeline library with GitHub source, I get the following sample:

       
      globalLibraries:
        libraries:
          - defaultVersion: "master"
            name: "jenkins-pipeline-lib"
            retriever:
               modernSCM:
                 scm:
                   github:
                     id: "e43d6600-ba0e-46c5-8eae-3989bf654055"
                     repoOwner: "jenkins-infra"
                     repository: "pipeline-library"
                     traits:
                       - branchDiscoveryTrait:
                           strategyId: 1
                       - originPullRequestDiscoveryTrait:
                            strategyId: 1
                       - forkPullRequestDiscoveryTrait:
                             strategyId: 1
                             trust: "trustPermission"

       

       When the same configuration is imported, I get 

      SEVERE: Failed ConfigurationAsCode.init java.lang.Error: java.lang.reflect.InvocationTargetException at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:110) at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175) at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296) at jenkins.model.Jenkins$5.runTask(Jenkins.java:1096) at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214) at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104) ... 8 more Caused by: io.jenkins.plugins.casc.ConfiguratorException: unclassified: error configuring 'unclassified' with class io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator configurator at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:633) at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:665) at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:649) at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:548) at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:277) at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:269) ... 13 more 
      
      Caused by: io.jenkins.plugins.casc.ConfiguratorException: Invalid configuration elements for type class jenkins.plugins.git.traits.BranchDiscoveryTrait : strategyId. Available attributes : at io.jenkins.plugins.casc.BaseConfigurator.handleUnknown(BaseConfigurator.java:372) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:361) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:271) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.configure(DataBoundConfigurator.java:79) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$doConfigure$16668e2$1(HeteroDescribableConfigurator.java:228) at io.vavr.CheckedFunction0.lambda$unchecked$52349c75$1(CheckedFunction0.java:201) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.doConfigure(HeteroDescribableConfigurator.java:228) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$null$2(HeteroDescribableConfigurator.java:82) at io.vavr.control.Option.map(Option.java:373) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$configure$3(HeteroDescribableConfigurator.java:82) at io.vavr.Tuple2.apply(Tuple2.java:239) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.configure(HeteroDescribableConfigurator.java:79) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.configure(HeteroDescribableConfigurator.java:51) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:340) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:271) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.configure(DataBoundConfigurator.java:79) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$doConfigure$16668e2$1(HeteroDescribableConfigurator.java:228) at io.vavr.CheckedFunction0.lambda$unchecked$52349c75$1(CheckedFunction0.java:201) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.doConfigure(HeteroDescribableConfigurator.java:228) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$null$2(HeteroDescribableConfigurator.java:82) at io.vavr.control.Option.map(Option.java:373) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$configure$3(HeteroDescribableConfigurator.java:82) at io.vavr.Tuple2.apply(Tuple2.java:239) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.configure(HeteroDescribableConfigurator.java:79) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.configure(HeteroDescribableConfigurator.java:51) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.tryConstructor(DataBoundConfigurator.java:130) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.instance(DataBoundConfigurator.java:73) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:262) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.configure(DataBoundConfigurator.java:79) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$doConfigure$16668e2$1(HeteroDescribableConfigurator.java:228) at io.vavr.CheckedFunction0.lambda$unchecked$52349c75$1(CheckedFunction0.java:201) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.doConfigure(HeteroDescribableConfigurator.java:228) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$null$2(HeteroDescribableConfigurator.java:82) at io.vavr.control.Option.map(Option.java:373) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.lambda$configure$3(HeteroDescribableConfigurator.java:82) at io.vavr.Tuple2.apply(Tuple2.java:239) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.configure(HeteroDescribableConfigurator.java:79) at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.configure(HeteroDescribableConfigurator.java:51) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.tryConstructor(DataBoundConfigurator.java:130) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.instance(DataBoundConfigurator.java:73) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:262) at io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator.check(DataBoundConfigurator.java:97) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:339) at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:282) at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:347) at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:282) at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$checkWith$6(ConfigurationAsCode.java:665) at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:627) ... 18 more
      

       

        Attachments

          Activity

          Hide
          fcojfernandez Francisco Fernández added a comment - - edited

          There is no issue importing the yaml file, at least with the latest version of the plugin: The sample file is not correct. The following is an example of exported yaml file using the latest versions of github-branch-sources and configuration-as-code.

          globalLibraries:
            libraries:
              - defaultVersion: "master"
                name: "jenkins-pipeline-lib"
                retriever:
                   modernSCM:
                     scm:
                       github:
                         id: "e43d6600-ba0e-46c5-8eae-3989bf654055"
                         repoOwner: "jenkins-infra"
                         repository: "pipeline-library"
                         traits:
                           - gitHubBranchDiscovery:
                               strategyId: 1
                           - originPullRequestDiscoveryTrait:
                                strategyId: 1
                           - gitHubForkDiscovery:
                                 strategyId: 1
                                 trust: "trustPermission"
          

          I will open a couple of PRs to test the compatibility.

           

          EDIT:

           

          Show
          fcojfernandez Francisco Fernández added a comment - - edited There is no issue importing the yaml file, at least with the latest version of the plugin: The sample file is not correct. The following is an example of exported yaml file using the latest versions of github-branch-sources and configuration-as-code . globalLibraries:   libraries:     - defaultVersion: "master"       name: "jenkins-pipeline-lib"       retriever:          modernSCM:            scm:              github:                id: "e43d6600-ba0e-46c5-8eae-3989bf654055"                repoOwner: "jenkins-infra"                repository: "pipeline-library"                traits:                  - gitHubBranchDiscovery:                      strategyId: 1                  - originPullRequestDiscoveryTrait:                       strategyId: 1                  - gitHubForkDiscovery:                        strategyId: 1                        trust: "trustPermission" I will open a couple of PRs to test the compatibility.   EDIT: ttps://github.com/jenkinsci/github-branch-source-plugin/pull/247 https://github.com/jenkinsci/configuration-as-code-plugin/pull/1071  
          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          Basically it looks like the class is not properly recovered from the array object.
          Invalid configuration elements for type class jenkins.plugins.git.traits.BranchDiscoveryTrait : strategyId. Available attributes : at io.jenkins.plugins.casc.BaseConfigurator.handleUnknown(BaseConfigurator.java:372) at
           

          stratagyId exists for child classes, but not for BranchDiscoveryTrait itself

          CC Joseph Petersen, likely this is an issue in the JCasC plugin

          Show
          oleg_nenashev Oleg Nenashev added a comment - Basically it looks like the class is not properly recovered from the array object. Invalid configuration elements for type class jenkins.plugins.git.traits.BranchDiscoveryTrait : strategyId. Available attributes : at io.jenkins.plugins.casc.BaseConfigurator.handleUnknown(BaseConfigurator.java:372) at   stratagyId exists for child classes, but not for BranchDiscoveryTrait itself CC Joseph Petersen , likely this is an issue in the JCasC plugin

            People

            • Assignee:
              fcojfernandez Francisco Fernández
              Reporter:
              oleg_nenashev Oleg Nenashev
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: