Home > Back-end >  Run two different sonar configurations in parallel with jenkins. Not sure how to create build.gradle
Run two different sonar configurations in parallel with jenkins. Not sure how to create build.gradle

Time:04-26

I am working on a project with multiple modules, lets say : bigModule, smallModuleA, smallModuleB and smallModuleC. And I have a build.gradle file which has sonar configuration that i change when i want to scan all small modules or the big module. I have a jenkins pipeline which has a sonar scan stage. My goal is to run two sonar scans with different configurations in parallel on jenkins. Now I know how to make two steps or stages run in parallel on jenkins. What my main concern is how would I have two sonar configurations on build.gradle file that that be referenced in each of those sonar stages that are being ran on jenkinsfile.

CodePudding user response:

One way to do it would be to parameterize the build:

if (hasProperty("do.scan.one")){
    sonarqube {
        properties {
            // do set up one
        }
    }
} else {
    sonarqube {
        properties {
            // do other set up
        }
    }
}

Then you would need to pass an additional command like argument in the non-default configuration:

./gradlew sonarqube -Pdo.scan.one

If it is easier to use environment variables, that is also possible. Just change the property check to a System.getenv() check.

  • Related