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

JCasC Groovy Script Failing that works in the Script Console

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • None
    • Jenkins 2.235.4
      configuration-as-code 1.42
      configuration-as-code-groovy 1.1

      Admittedly I am new to this plugin butt he below JCasC yaml snippet works in the script console but results in an error when run by JCasC:

            jenkins-groovy: |
              groovy:
                - script: >
                   // Set SVN Workspace Version;
                   import jenkins.model.*
                   def instance = Jenkins.getInstance()
      
                   println("This is Groovy script!") ;
                   def required_format = 31;
                   desc = instance.getDescriptor("hudson.scm.SubversionSCM");
                   if (desc.getWorkspaceFormat() != required_format) {
                         def wf = desc.getClass().getDeclaredField("workspaceFormat");
                         wf.setAccessible(true);
                         wf.set(desc, required_format);
                         wf.setAccessible(false)};
                   println("This is Groovy script!") ;
      

      The Error:

      This is Groovy script!
      2020-08-14 22:58:52.552+0000 [id=27]	SEVERE	jenkins.InitReactorRunner$1#onTaskFailed: Failed ConfigurationAsCode.init
      groovy.lang.MissingPropertyException: No such property: instance for class: Configuration-as-Code-Groovy
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
      	at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
      	at Configuration-as-Code-Groovy.run(Configuration-as-Code-Groovy:2)
      	at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:518)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:497)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:170)
      	at io.jenkins.plugins.cascgroovy.GroovyScriptCaller.configure(GroovyScriptCaller.java:83)
      Caused: io.jenkins.plugins.casc.ConfiguratorException: groovy: Failed to execute script with hash -468718335
      	at io.jenkins.plugins.cascgroovy.GroovyScriptCaller.configure(GroovyScriptCaller.java:88)
      	at io.jenkins.plugins.cascgroovy.GroovyScriptCaller.configure(GroovyScriptCaller.java:33)
      	at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$configureWith$6(ConfigurationAsCode.java:747)
      	at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:691)
      Caused: io.jenkins.plugins.casc.ConfiguratorException: groovy: error configuring 'groovy' with class io.jenkins.plugins.cascgroovy.GroovyScriptCaller configurator
      	at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:697)
      	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:747)
      	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:616)
      	at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:298)
      	at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:290)
      Caused: 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)
      Caused: java.lang.Error
      	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:1131)
      	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
      	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
      	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
      	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)
      2020-08-14 22:58:52.556+0000 [id=19]	SEVERE	hudson.util.BootFailure#publish: Failed to initialize Jenkins
      

            szandala Tomasz SzandaƂa
            daxgames Dax Games
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: