Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Jenkin's SonarQube section using Job-DSL

Using Job-DSL we can configure a C# project in Jenkins.

The SonarQube tasks is giving us a hard time.

        StepContext.metaClass.sonar = {
        -> NodeBuilder nodeBuilder = new NodeBuilder()
            stepNodes << nodeBuilder.'hudson.plugins.sonar.SonarRunnerBuilder' {
                jdk('(Inherit From Job)')
                usePrivateRepository(false)
            }
    }

How to set the path to the sonar-project.properties config file, using the Job-DSL script?

Sonar section

Final script

Thanks to @Bruno César, I added pathToSonarProjectProperties as parameter.

    StepContext.metaClass.sonar = { String pathToSonarProjectProperties
        -> NodeBuilder nodeBuilder = new NodeBuilder()
            stepNodes << nodeBuilder.'hudson.plugins.sonar.SonarRunnerBuilder' {
                jdk('(Inherit From Job)')
                usePrivateRepository(false)
                project(pathToSonarProjectProperties)
            }
    }

The sonar function is called with the relative-to-project-root path of sonar-project.properties:

sonar("Framework\\xxx\\xxx\\sonar-project.properties")
like image 623
Francois Avatar asked Apr 27 '15 15:04

Francois


1 Answers

In SonarRunnerBuilder class there is a project attribute that represents the path to a file with properties for the project.

In the same way in which you set the JDK (jdk('(Inherit From Job)')) you can set the path property. In your example, try like this:

StepContext.metaClass.sonar = {
    -> NodeBuilder nodeBuilder = new NodeBuilder()
    stepNodes << nodeBuilder.'hudson.plugins.sonar.SonarRunnerBuilder' {
        jdk('(Inherit From Job)')
        usePrivateRepository(false)
        project('${your.path.here}')
    }
}
like image 59
Bruno Ribeiro Avatar answered Nov 14 '22 03:11

Bruno Ribeiro