I'm having a hard time running Groovy scripts in Jenkins.

 - I've configured Groovy 2.4.5 and chosen a Groovy command (as opposed to 
script)
 - Copied JAR files from jenkins.war to u01/opt/groovy/2.4.5/lib/jenkins
 - I have tried specifying the Jenkin JARs in the plugin classpath as well 
(per example below)

Here is the job (admittedly, partially copied from an example online):

    import jenkins.model.Jenkins
    Jenkins jenkins = Jenkins.getInstance()
    
    println "Hello world!"

Setup:

 - Jenkins 1.647

Error I get, which always crops up when I attempt to use 
Jenkins.getInstance():

    Started by user Me
    Building in workspace /var/lib/jenkins/jobs/GroovyTest/workspace
    [workspace] $ /u01/opt/groovy/2.4.5/bin/groovy -cp 
/u01/opt/groovy/2.4.5/lib/jenkins 
/var/lib/jenkins/jobs/GroovyTest/workspace/hudson6830454431875893184.groovy
    Feb 22, 2016 11:08:55 AM jenkins.model.Jenkins <clinit>
    SEVERE: Failed to load Jenkins.class
    java.lang.NoSuchMethodError: 
hudson.util.XStream2.getConverterRegistry()Lcom/thoughtworks/xstream/converters/ConverterRegistry;
        at hudson.util.XStream2.wrapMapper(XStream2.java:185)
        at com.thoughtworks.xstream.XStream.buildMapper(XStream.java:610)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:568)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:496)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:465)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:411)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:350)
        at hudson.util.XStream2.<init>(XStream2.java:88)
        at jenkins.model.Jenkins.<clinit>(Jenkins.java:4308)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:270)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray$1.run(CallSiteArray.java:68)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray$1.run(CallSiteArray.java:65)
        at java.security.AccessController.doPrivileged(Native Method)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:65)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:162)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
        at hudson6830454431875893184.run(hudson6830454431875893184.groovy:2)
        at 
groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
        at groovy.lang.GroovyShell.run(GroovyShell.java:524)
        at groovy.lang.GroovyShell.run(GroovyShell.java:513)
        at groovy.ui.GroovyMain.processOnce(GroovyMain.java:652)
        at groovy.ui.GroovyMain.run(GroovyMain.java:384)
        at groovy.ui.GroovyMain.process(GroovyMain.java:370)
        at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)
        at groovy.ui.GroovyMain.main(GroovyMain.java:109)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at 
org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
        at 
org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
    
    Caught: java.lang.NoSuchMethodError: 
hudson.util.XStream2.getConverterRegistry()Lcom/thoughtworks/xstream/converters/ConverterRegistry;
    java.lang.NoSuchMethodError: 
hudson.util.XStream2.getConverterRegistry()Lcom/thoughtworks/xstream/converters/ConverterRegistry;
        at hudson.util.XStream2.wrapMapper(XStream2.java:185)
        at com.thoughtworks.xstream.XStream.buildMapper(XStream.java:610)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:568)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:496)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:465)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:411)
        at com.thoughtworks.xstream.XStream.<init>(XStream.java:350)
        at hudson.util.XStream2.<init>(XStream2.java:88)
        at jenkins.model.Jenkins.<clinit>(Jenkins.java:4308)
        at hudson6830454431875893184.run(hudson6830454431875893184.groovy:2)
    Build step 'Execute Groovy script' marked build as failure
    Finished: FAILURE

Screenshot of configuration
http://i.stack.imgur.com/TVb7G.png

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/3b2ed12a-fe64-4dd2-92ce-bf81151130bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to