2

I'm using the following script to do a Rest call. I have it working on another Jenkins rig and am now improving the script to make it reusable on another rig, but I'm getting an exception thrown. The code I'm having an issue with is the following. It looks like it's blowing up on the "new HTTPBuilder()" construction, but I can't figure out why:

public postTestRun(Map rp) {
   def writer = new StringWriter()
   def bldr = new groovy.xml.MarkupBuilder(new StringWriter())
   def http = new HTTPBuilder(restUrl)
   bldr.getMkp().xmlDeclaration(version: "1.0", encoding: "UTF-8", standalone: "yes")
   bldr.Entity(Type: "run") {

The stack trace I'm getting is as follows:

FATAL: groovy/lang/Closure java.lang.NoClassDefFoundError: groovy/lang/Closure at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getDeclaredMethods(Unknown Source) at org.codehaus.groovy.reflection.CachedClass$3$1.run(CachedClass.java:84) at java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:81) at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:79) at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46) at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33) at org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:250) at groovy.lang.MetaClassImpl.populateMethods(MetaClassImpl.java:307) at groovy.lang.MetaClassImpl.fillMethodIndex(MetaClassImpl.java:286) at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:2936) at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:166) at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:182) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:227) at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:751) at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:71) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190) at Utms.postTestRun(Utms.groovy:21) at Utms$postTestRun.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at JenkinsTestLogger.logTestResult(JenkinsTestLogger.groovy:56) at JenkinsTestLoggerIf$logTestResult.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at Script1.run(Script1.groovy:37) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:650) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:636) at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:98) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:756) at hudson.model.Build$BuildExecution.build(Build.java:198) at hudson.model.Build$BuildExecution.doRun(Build.java:159) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529) at hudson.model.Run.execute(Run.java:1706) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:232) Caused by: java.lang.ClassNotFoundException: groovy.lang.Closure at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 44 more

Joel
  • 111
  • 13
  • Looks like groovy is missing from the instance that's trying to run that – tim_yates Aug 13 '15 at 21:40
  • It's running a groovy script and instantiating a number of groovy classes before it gets to this point, so I don't think that's the problem. Also, if I comment out the "new HTTBuilder" line then the program doesn't throw the exception – Joel Aug 14 '15 at 00:59
  • I think I may know what's going on, but I'm not sure. Your comment about groovy missing got me to thinking. What if it's a version problem? I definitely have groovy running, but what if the version of HTTPBuilder I have isn't compatible with it? On my other Jenkins server I have versions 2.1.3 and 2.2.1 installed. On this server, only 2.1.3 is installed. So perhaps I need to install the other version. But, do system Groovy scripts only run using the default Groovy version, which in this case would be 2.1.3? If so, how can I change that? – Joel Aug 14 '15 at 14:29
  • I discovered what the problem is. After a lot of playing with it, I discovered that Jenkins has Groovy 1.8.5 embedded in it, and since I'm using a System Groovy script, that's the version that's being used. In order to perform this functionality, it would need to be implemented in a non-System Groovy script with the Groovy version specified. – Joel Sep 22 '15 at 22:16

1 Answers1

2

Problem Solved, Use a non-system Groovy Script and specify the Groovy version to use.

Joel
  • 111
  • 13