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

A wrong configuration of CasC yaml kill Jenkins startup

    Details

    • Similar Issues:

      Description

      While testing the CasC plugin I've found that if the yaml is wrong, Jenkins stop restarting, leaving you with an unoperational instance.

      Steps to reproduce:

      • Create a yaml with ssh credentials
      • Import this yaml
      • Remove credentials and ssh-credentials
      • Restart Jenkins

      Expected:

      • Some settings are established, others not.

      Current behavior:

      • Jenkins doesn't start.

       

      Jun 05, 2019 5:27:03 PM jenkins.InitReactorRunner$1 onTaskFailed
      Jun 05, 2019 5:27:03 PM jenkins.InitReactorRunner$1 onTaskFailed 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: No configurator for root element <credentials>
       at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:642)
       at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:666)
       at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:650)
       at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:549)
       at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:277)
       at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:269) ... 13 more
      Jun 05, 2019 5:27:03 PM hudson.util.BootFailure publish SEVERE: Failed to initialize Jenkins
      hudson.util.HudsonFailedToLoad: org.jvnet.hudson.reactor.ReactorException: java.lang.Error: java.lang.reflect.InvocationTargetException
       at hudson.WebAppMain$3.run(WebAppMain.java:250)
      Caused by: org.jvnet.hudson.reactor.ReactorException: java.lang.Error: java.lang.reflect.InvocationTargetException
       at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:282)
       at jenkins.InitReactorRunner.run(InitReactorRunner.java:48)
       at jenkins.model.Jenkins.executeReactor(Jenkins.java:1130)
       at jenkins.model.Jenkins.<init>(Jenkins.java:932)
       at hudson.model.Hudson.<init>(Hudson.java:85)
       at hudson.model.Hudson.<init>(Hudson.java:81)
       at hudson.WebAppMain$3.run(WebAppMain.java:233)
      Caused by: 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: No configurator for root element <credentials>
       at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:642)
       at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:666)
       at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:650)
       at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:549)
       at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:277)
       at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:269) ... 13 more
      Jun 05, 2019 5:27:03 PM jenkins.model.Jenkins cleanUp INFO: Stopping Jenkins
      Jun 05, 2019 5:27:03 PM jenkins.model.Jenkins$18 onAttained INFO: Started termination
      Jun 05, 2019 5:27:03 PM jenkins.model.Jenkins$18 onAttained INFO: Completed termination
      Jun 05, 2019 5:27:03 PM jenkins.model.Jenkins _cleanUpDisconnectComputers INFO: Starting node disconnection
      Jun 05, 2019 5:27:03 PM jenkins.model.Jenkins _cleanUpShutdownPluginManager INFO: Stopping plugin manager
      Jun 05, 2019 5:27:03 PM jenkins.model.Jenkins _cleanUpPersistQueue INFO: Persisting build queue
      Jun 05, 2019 5:27:03 PM jenkins.model.Jenkins _cleanUpAwaitDisconnects INFO: Waiting for node disconnection completion
      Jun 05, 2019 5:27:03 PM jenkins.model.Jenkins cleanUp INFO: Jenkins stopped
      

        Attachments

          Activity

          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          Ramon Leon for this plugin it is better to duplicate the issue in https://github.com/jenkinsci/configuration-as-code-plugin/issues

          Show
          oleg_nenashev Oleg Nenashev added a comment - Ramon Leon for this plugin it is better to duplicate the issue in  https://github.com/jenkinsci/configuration-as-code-plugin/issues
          Show
          mramonleon Ramon Leon added a comment - https://github.com/jenkinsci/configuration-as-code-plugin/issues/912
          Hide
          mramonleon Ramon Leon added a comment -

          Also if the yaml file is removed you have to edit io.jenkins.plugins.casc.CasCGlobalConfig.xml to remove the file.

          Show
          mramonleon Ramon Leon added a comment - Also if the yaml file is removed you have to edit io.jenkins.plugins.casc.CasCGlobalConfig.xml to remove the file.
          Hide
          rudolfwg Rudolf-Walter Kiss-Szakacs added a comment -

          [Originally posted on the associated GitHub issue, replicating here for visibility.]

          I have personally worked around this by applying CasC configs through a job, and disabling CasC for Jenkins startup by pointing it to an empty file.

          That is, I have a job that does a SCM checkout, and then runs something like this as a system-groovy script (from the groovy plugin):

          import jenkins.model.GlobalConfiguration
          import io.jenkins.plugins.casc.ConfigurationAsCode
          import io.jenkins.plugins.casc.CasCGlobalConfig
          def workspacePath = build.environment.WORKSPACE
          def jcascConfig = GlobalConfiguration.all().get(CasCGlobalConfig.class)
          try {
          	jcascConfig.setConfigurationPath(workspacePath)
          	jcascConfig.save()
          	ConfigurationAsCode.get().configure()
          } finally {
          	jcascConfig.setConfigurationPath("${workspacePath}/empty.yaml")
          	jcascConfig.save()
          }
          

          (Note that below CasC version 1.20, you need to have at least one setting in empty.yaml, a completely empty file generates a null pointer exception.)

          Show
          rudolfwg Rudolf-Walter Kiss-Szakacs added a comment - [Originally posted on the associated GitHub issue, replicating here for visibility.] I have personally worked around this by applying CasC configs through a job, and disabling CasC for Jenkins startup by pointing it to an empty file. That is, I have a job that does a SCM checkout, and then runs something like this as a system-groovy script (from the groovy plugin): import jenkins.model.GlobalConfiguration import io.jenkins.plugins.casc.ConfigurationAsCode import io.jenkins.plugins.casc.CasCGlobalConfig def workspacePath = build.environment.WORKSPACE def jcascConfig = GlobalConfiguration.all().get(CasCGlobalConfig.class) try { jcascConfig.setConfigurationPath(workspacePath) jcascConfig.save() ConfigurationAsCode.get().configure() } finally { jcascConfig.setConfigurationPath( "${workspacePath}/empty.yaml" ) jcascConfig.save() } (Note that below CasC version 1.20, you need to have at least one setting in empty.yaml , a completely empty file generates a null pointer exception.)

            People

            • Assignee:
              ewel Ewelina Wilkosz
              Reporter:
              mramonleon Ramon Leon
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: