Scanning Gradle build with multiple modules

Hi Everyone,

What I’m trying to do:
Scan a Gradle multi module project via Jenkins pipeline. Here is my Jenkinsfile code for the scan:

Stage("Sonar") {
	if (RUN_SONAR == false) {
	sh """
		rm /users/something/.gradle/caches/5.4.1/fileHashes/fileHashes.lock || true
		rm /users/something/.gradle/caches/journal-1/journal-1.lock || true
		./gradlew ${PROXY_GRADLE_OPTS} --no-daemon sonarqube 
	withSonarQubeEnv() {
		sh "./gradlew ${PROXY_GRADLE_OPTS} --no-daemon sonarqube"}
	timeout(time: 1, unit: 'HOURS') { /
		def qg = waitForQualityGate() 
		if (qg.status != 'OK') {
		error "Pipeline aborted due to quality gate failure: ${qg.status}"
} // End Sonar Stage

What happens is that the process scans all 4 modules but then the waitForQualityGate() only gets back result for one of the scans (see log)

WARN: Found multiple ‘report-task.txt’ in the workspace. Taking the first one.
[Pipeline] // withSonarQubeEnv
[Pipeline] sleep
Sleeping for 15 sec
[Pipeline] timeout
Timeout set to expire in 1 hr 0 min
[Pipeline] {
[Pipeline] waitForQualityGate
Checking status of SonarQube task ‘AW5kx-_DIFBOU4d86ZSQ’ on server ‘ATTSonarQube’
SonarQube task ‘AW5kx-_DIFBOU4d86ZSQ’ status is ‘SUCCESS’
SonarQube task ‘AW5kx-_DIFBOU4d86ZSQ’ completed. Quality gate is ‘OK’

How can i direct the scanner so it will know it should pick up all 4 modules that got scanned?

Thanks in advance,

Versions that i’m using:
Sonarqube Version 6.7.6 (build 38781)
SonarQube Scanner for Jenkins v2.8.1


Welcome to the community!

You’ll find an example pipeline at the end of page in the Scanner for Jenkins docs.


Hi @ganncamp ,
I did follow that example but my issue is since there are 4 submodels in the gradle project multiple ‘report-task.txt’ files are created in the workspace for each module and for some reason the Sonar Plug in only picks up the results of one of them.

I managed to by pass this issue by running a sonar scan on each module and right after i finish with the waitForQualityGate() function i delete the relevent report-task.txt file for that scan.

Have the same issue and ended with similar not-so-elegant workaround:

stage("Quality Gate") {
    ["module1", "module2"].each { module ->
        withSonarQubeEnv('sonar-1') {
            sh "./gradlew :$module:sonarqube"

        timeout(time: 1, unit: 'HOURS') {
            def qg = waitForQualityGate()
            if (qg.status != 'OK') {
                unstable "Pipeline quality gate failure: ${qg.status}"

        dir("$module/build/sonar") {

Interesting did authors consider multi-module builds in this plugin? because some people use it :slight_smile:

1 Like

Hi Alexander,
I did that but i didn’t delete the entire dir i just deleted the “common/build/sonar/report-task.txt” file. But then instead of a minute 1.30 for that stage to run for 4 modules it took 6 minutes to run which is to much for my Developers.

Im still stuck on this by the way.