Error submitting Free Style Job configuration if an SCM is not applicable

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor
    • Component/s: core
    • Environment:
      Jenkins 2.401.1 (but confirmed the problem with current Jenkins source code)

      Configuring a free style job can throw an exception if there is an SCM implementation is not applicable. Here's the setup:

      • A custom SCM plugin that only supports WorkflowJob. The SCMDescriptor implements the isApplicable method to only return true for WorkflowJobs:

          @Extension
          public static class DescriptorImpl extends SCMDescriptor<MySCM> {
      {{        }}
              @Override
              public boolean isApplicable(Job project) {
                  return project instanceof WorkflowJob;
      {{        }}}
              //...
      {{    }}}

      • Create a new Free Style Job. It drops you into the configuration page. Choose an SCM: it must be one that would have come after the custom SCM if it were applicable. Saving the configuration should return an error.

       

      Tracing through the Jenkins code:

      • Rendering the Free Style Job configuration page uses config-scm.jelly, which uses Functions.getSCMDescriptors --> SCM._for, which filters descriptors by isApplicable. Notably, the radio buttons are assigned values from 0 to n-1, as if the filtered descriptors don't exist
      • Submitting the Free Style Job configuration page uses SCMS.parseSCM --> DescriptorExtensionList.newInstanceFromRadioList, which does not filter the SCM descriptors. It directly uses the radio button value to index into SCM.all()

      The result is Jenkins potentially trying to create the wrong SCM implementation, because the config page SCM radio button indices don't necessarily line up with the descriptor list returned from SCM.all().

       

      Here's an example exception:

      java.lang.IllegalArgumentException: Specified type class hudson.plugins.git.GitSCM is not assignable to the expected class com.example.MySCM
              at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:759)
      {{Caused: java.lang.IllegalArgumentException: Failed to instantiate class com.example.MySCM from {"value":"1","stapler-class":"hudson.plugins.git.GitSCM","$class":"hudson.plugins.git.GitSCM","userRemoteConfigs":

      {"url":"<url>","includeUser":"false","credentialsId":"<url>","name":"","refspec":""}

      ,"branches":{"name":"*/master"},"gitTool":"jgit","":"auto"}}}
              at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:769)
              at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:549)
              at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:544)
              at hudson.model.Descriptor.bindJSON(Descriptor.java:622)
              at hudson.model.Descriptor.newInstance(Descriptor.java:592)

      {{Caused: java.lang.LinkageError: Failed to instantiate class com.example.MySCM from {"value":"1","stapler-class":"hudson.plugins.git.GitSCM","$class":"hudson.plugins.git.GitSCM","userRemoteConfigs":

      {"url":"<url>","includeUser":"false","credentialsId":"<creds>","name":"","refspec":""}

      ,"branches":{"name":"*/master"},"gitTool":"jgit","":"auto"}}}
              at hudson.model.Descriptor.newInstance(Descriptor.java:595)
              at hudson.DescriptorExtensionList.newInstanceFromRadioList(DescriptorExtensionList.java:148)
              at hudson.scm.SCMS.parseSCM(SCMS.java:57)
              at hudson.model.AbstractProject.submit(AbstractProject.java:1825)
              at hudson.model.Project.submit(Project.java:228)
              at hudson.model.Job.doConfigSubmit(Job.java:1348)
              at hudson.model.AbstractProject.doConfigSubmit(AbstractProject.java:772)
              at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)

            Assignee:
            Unassigned
            Reporter:
            Keith Johnson
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: