Jenkins groovy init script for sonarqube configuration

727 views
Skip to first unread message

ajaysing...@gmail.com

unread,
May 4, 2018, 4:47:25 PM5/4/18
to Jenkins Users
I am trying to set sonarqube settings in Jenkins system property using groovy init script but I am getting below error. Can somebody help me to resolve this?

Error
+++++

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: 
hudson.plugins.sonar.SonarInstallation(java.lang.String, java.lang.String, 
java.lang.String, hudson.plugins.sonar.model.TriggersConfig, 
java.lang.String)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1732)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1532)

This is the script that I am using

import hudson.model.*
import jenkins.model.*
import hudson.plugins.sonar.SonarGlobalConfiguration
import hudson.plugins.sonar.*
import hudson.plugins.sonar.model.TriggersConfig
import hudson.tools.*

def inst = Jenkins.getInstance()

println "--> Configuring SonarQube"

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

def sonar_inst = new SonarInstallation(
    "SonarQ",
    "http://localhost:9000",
    "yy", // Token
    new TriggersConfig(),
    ""
)

// Only add ADOP Sonar if it does not exist - do not overwrite existing config
def sonar_installations = sonar_conf.getInstallations()
def sonar_inst_exists = false
sonar_installations.each {
    installation = (SonarInstallation) it
    if (sonar_inst.getName() == installation.getName()) {
        sonar_inst_exists = true
        println("Found existing installation: " + installation.getName())
    }
}

if (!sonar_inst_exists) {
    sonar_installations += sonar_inst
    sonar_conf.setInstallations((SonarInstallation[]) sonar_installations)
    sonar_conf.save()
}

Victor Martinez

unread,
May 4, 2018, 5:04:32 PM5/4/18
to Jenkins Users
what version of the sonar plugin is installed? 

It looks like the current constructor is not just 5 parameters based but a lot of more:

Cheers

Ajay Singh

unread,
May 7, 2018, 12:06:05 AM5/7/18
to jenkins...@googlegroups.com
Thanks Victor,

The issue got resolved. The problem was with the no of parameters. It was expecting 7 parameters.

--
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/27d82b76-a87b-4b77-8710-a1dbe11eabb7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

naveen

unread,
May 18, 2018, 3:06:12 PM5/18/18
to Jenkins Users

I'm getting error in groovy script configure the Sonar plugin. Here is my script.










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()


and when I run this script throwing me an an 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 please me in this script.
Reply all
Reply to author
Forward
0 new messages