Jenkins Sonar Plugin groovy script

45 views
Skip to first unread message

naveen

unread,
May 18, 2018, 3:06:12 PM5/18/18
to Jenkins Users
When I tried to configure Sonar plugin using following script throwing me an error.








import jenkins.model.*


import hudson.plugins.sonar.*


import hudson.plugins.sonar.model.*




def inst = Jenkins.getInstance()


SonarGlobalConfiguration global = Hudson.instance.getDescriptorByType(SonarGlobalConfiguration.class)


def sinst = new SonarInstallation(


  "sonar",


  "http://localhost:9000/",


  "yyyyyyyyyyyyyy",


  "3.2",


  "",


  new TriggersConfig(),


  ""


)


desc.setInstallations(sinst)




desc.save()

 ERROR








ERROR: Unexpected exception occurred while performing groovy command.


groovy.lang.MissingPropertyException: No such property: Hudson for class: RemoteClass


        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 RemoteClass.run(RemoteClass:6)


        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 hudson.cli.GroovyCommand.run(GroovyCommand.java:89)


        at hudson.cli.CLICommand.main(CLICommand.java:278)


        at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:95)

Could someone help me in solving this script. It might be an constructor issue.

Thanks!


Eric Pyle

unread,
May 18, 2018, 4:15:27 PM5/18/18
to Jenkins Users
Hi Naveen,

It looks like you need to import hudson.model.* to get class Hudson.

Eric

--
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 jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7b3e5b1f-f8e4-4fcb-8cfd-c6822d573175%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Eric Pyle
Siemens PLM Software
Lebanon, New Hampshire
+1 603-277-3060 (T)
eric...@siemens.com
http://www.siemens.com 

naveen

unread,
May 18, 2018, 4:23:46 PM5/18/18
to Jenkins Users
Hello, Thanks for replaying me back.  Tried with your suggestion got new error 








ERROR: Unexpected exception occurred while performing groovy command.


groovy.lang.MissingPropertyException: No such property: desc for class: RemoteClass


        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 RemoteClass.run(RemoteClass:17)


        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 hudson.cli.GroovyCommand.run(GroovyCommand.java:89)


        at hudson.cli.CLICommand.main(CLICommand.java:278)


        at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:95)


        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.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:927)


        at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:901)


        at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:850)


        at hudson.remoting.UserRequest.perform(UserRequest.java:210)


        at hudson.remoting.UserRequest.perform(UserRequest.java:53)


Something wrong in code i'm missing that.

naveen

unread,
May 18, 2018, 4:24:10 PM5/18/18
to Jenkins Users









ERROR: Unexpected exception occurred while performing groovy command.


groovy.lang.MissingPropertyException: No such property: desc for class: RemoteClass


        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 RemoteClass.run(RemoteClass:17)


        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 hudson.cli.GroovyCommand.run(GroovyCommand.java:89)


        at hudson.cli.CLICommand.main(CLICommand.java:278)


        at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:95)


        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.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:927)


        at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:901)


        at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:850)


        at hudson.remoting.UserRequest.perform(UserRequest.java:210)


        at hudson.remoting.UserRequest.perform(UserRequest.java:53)



naveen

unread,
May 18, 2018, 4:25:57 PM5/18/18
to Jenkins Users
By chance could review the code once, any suggestions.

Victor Martinez

unread,
May 18, 2018, 4:42:19 PM5/18/18
to Jenkins Users
Well.. the stacktrace message is quite clear:

groovy.lang.MissingPropertyException: No such property: desc for class: RemoteClass


Worth to look for where 'desc' is declared/instanced as it's not part of the snippet you pasted it. Likely you could find some answers in this code:

Cheers

naveen

unread,
May 18, 2018, 4:45:25 PM5/18/18
to Jenkins Users
Thanks so much! well it worked 








import jenkins.model.*


import hudson.plugins.sonar.*


import hudson.plugins.sonar.model.*


import hudson.model.*




def inst = Jenkins.getInstance()


SonarGlobalConfiguration global = Hudson.instance.getDescriptorByType(SonarGlobalConfiguration.class)


def sinst = new SonarInstallation(


  "sonar",


  "http://localhost:9000/",


  "yyyyyyyyyyyyyy",


  "3.2",


  "",


  new TriggersConfig(),


  ""


)


global.setInstallations(sinst)




global.save()

Eric Pyle

unread,
May 18, 2018, 4:50:30 PM5/18/18
to Jenkins Users
Here again the error message is pretty clear. Groovy can't find the object "desc". Judging by the name, this is probably a Descriptor you are looking for. You set the variable "global" as an instance of SonarGlobalConfiguration, a subclass of Descriptor, using getDescriptorByType():

SonarGlobalConfiguration global = Hudson.instance.getDescriptorByType(SonarGlobalConfiguration.class)

Perhaps you should name that variable "desc", like this:

SonarGlobalConfiguration desc =  Hudson.instance.getDescriptorByType(SonarGlobalConfiguration.class)

Then you will have a valid object "desc" for later on in your script. Refer to http://javadoc.jenkins.io/plugin/sonar/ and http://javadoc.jenkins.io/.

-Eric



--
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 jenkinsci-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages