Search code examples
javagradlesonarqubejenkins-pipelinebuild.gradle

Run two different sonar configurations in parallel with jenkins?


I am working on a project with multiple modules, let's say: big module, smallModuleA, small modules, and small modules. And I have a build. Gradle file which has a sonar configuration that I change when I want to scan all small modules or the big module. I have a Jenkins pipeline that 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. My main concern is how would I have two sonar configurations on the build. The Gradle file that that be referenced in each of those sonar stages that are being run on the Jenkins file.


Solution

  • 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.