From 4f3c8253631c0a51283cfdd98a4b0b5d0e63578b Mon Sep 17 00:00:00 2001 From: Dinesh Patel Date: Thu, 26 Feb 2026 12:51:01 +0000 Subject: [PATCH 1/5] added sonar reporting --- Jenkinsfile_CNP | 24 ++++++++++++++++++++++++ Jenkinsfile_nightly | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/Jenkinsfile_CNP b/Jenkinsfile_CNP index 518958d583..24248b90d2 100644 --- a/Jenkinsfile_CNP +++ b/Jenkinsfile_CNP @@ -158,6 +158,7 @@ withPipeline(type, product, component) { steps.archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/checkstyle/*.html' steps.archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/pmd/*.html' + archiveSonarArtifacts() copyIgnore('./build/reports/tests/integration', './Integration Tests/') steps.archiveArtifacts allowEmptyArchive: true, artifacts: '**/Integration Tests/**/*' @@ -251,3 +252,26 @@ withPipeline(type, product, component) { def copyIgnore(filePath, destinationDir) { steps.sh("cp -R '${filePath}' '${destinationDir}' || :") } + +def archiveSonarArtifacts() { + def sonarTaskReport = 'build/sonar/report-task.txt' + steps.archiveArtifacts allowEmptyArchive: true, artifacts: 'build/sonar/**,.scannerwork/report-task.txt' + + if (steps.fileExists(sonarTaskReport)) { + def dashboardLine = steps.readFile(sonarTaskReport).readLines().find { it.startsWith('dashboardUrl=') } + if (dashboardLine) { + steps.echo "SonarQube dashboard: ${dashboardLine.substring('dashboardUrl='.length())}" + } else { + steps.echo "Sonar report task file archived but dashboardUrl is missing in ${sonarTaskReport}" + } + } else if (steps.fileExists('.scannerwork/report-task.txt')) { + def dashboardLine = steps.readFile('.scannerwork/report-task.txt').readLines().find { it.startsWith('dashboardUrl=') } + if (dashboardLine) { + steps.echo "SonarQube dashboard: ${dashboardLine.substring('dashboardUrl='.length())}" + } else { + steps.echo "Sonar report task file archived but dashboardUrl is missing in .scannerwork/report-task.txt" + } + } else { + steps.echo 'Sonar task report not found to archive.' + } +} diff --git a/Jenkinsfile_nightly b/Jenkinsfile_nightly index 3812977cde..bf76a35014 100644 --- a/Jenkinsfile_nightly +++ b/Jenkinsfile_nightly @@ -269,6 +269,7 @@ withNightlyPipeline(type, product, component) { afterAlways('test') { // hmcts/cnp-jenkins-library may fail to copy artifacts after checkstyle error so repeat command (see /src/uk/gov/hmcts/contino/GradleBuilder.groovy) steps.archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/checkstyle/*.html' + archiveSonarArtifacts() } enableFullFunctionalTest(200) @@ -278,3 +279,26 @@ withNightlyPipeline(type, product, component) { } enableSlackNotifications('#ccd-nightly-builds') } + +def archiveSonarArtifacts() { + def sonarTaskReport = 'build/sonar/report-task.txt' + steps.archiveArtifacts allowEmptyArchive: true, artifacts: 'build/sonar/**,.scannerwork/report-task.txt' + + if (steps.fileExists(sonarTaskReport)) { + def dashboardLine = steps.readFile(sonarTaskReport).readLines().find { it.startsWith('dashboardUrl=') } + if (dashboardLine) { + steps.echo "SonarQube dashboard: ${dashboardLine.substring('dashboardUrl='.length())}" + } else { + steps.echo "Sonar report task file archived but dashboardUrl is missing in ${sonarTaskReport}" + } + } else if (steps.fileExists('.scannerwork/report-task.txt')) { + def dashboardLine = steps.readFile('.scannerwork/report-task.txt').readLines().find { it.startsWith('dashboardUrl=') } + if (dashboardLine) { + steps.echo "SonarQube dashboard: ${dashboardLine.substring('dashboardUrl='.length())}" + } else { + steps.echo "Sonar report task file archived but dashboardUrl is missing in .scannerwork/report-task.txt" + } + } else { + steps.echo 'Sonar task report not found to archive.' + } +} From c506ad84282ecbbb095f03836fe6b3b23aab4168 Mon Sep 17 00:00:00 2001 From: Dinesh Patel Date: Thu, 26 Feb 2026 13:20:19 +0000 Subject: [PATCH 2/5] patch to force sonar job --- Jenkinsfile_CNP | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile_CNP b/Jenkinsfile_CNP index 24248b90d2..51da71b5f4 100644 --- a/Jenkinsfile_CNP +++ b/Jenkinsfile_CNP @@ -155,6 +155,8 @@ withPipeline(type, product, component) { // hmcts/cnp-jenkins-library may fail to copy artifacts after checkstyle error so repeat command (see /src/uk/gov/hmcts/contino/GradleBuilder.groovy) builder.gradle('integration') + builder.gradle('jacocoTestReport') + builder.gradle('sonarqube') steps.archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/checkstyle/*.html' steps.archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/pmd/*.html' diff --git a/build.gradle b/build.gradle index b709391a03..b8559d4d9d 100644 --- a/build.gradle +++ b/build.gradle @@ -567,7 +567,7 @@ sonarqube { "**/TestingSupportController.java" property "sonar.projectName", "ccd-data-store-api" property "sonar.projectKey", "ccd-data-store-api" - property "sonar.coverage.jacoco.xmlReportPaths", "${jacocoTestReport.reports.xml.outputLocation}" + property "sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/reports/jacoco/test/jacocoTestReport.xml" } } From b2d08ac3ace05101286cbdd78c74dc7c1619c8c5 Mon Sep 17 00:00:00 2001 From: Dinesh Patel Date: Thu, 26 Feb 2026 13:34:12 +0000 Subject: [PATCH 3/5] added config --- Jenkinsfile_CNP | 2 +- build.gradle | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile_CNP b/Jenkinsfile_CNP index 51da71b5f4..b7d9c36ec2 100644 --- a/Jenkinsfile_CNP +++ b/Jenkinsfile_CNP @@ -156,7 +156,7 @@ withPipeline(type, product, component) { builder.gradle('integration') builder.gradle('jacocoTestReport') - builder.gradle('sonarqube') + builder.gradle('sonar') steps.archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/checkstyle/*.html' steps.archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/pmd/*.html' diff --git a/build.gradle b/build.gradle index b8559d4d9d..7b4c400094 100644 --- a/build.gradle +++ b/build.gradle @@ -567,6 +567,7 @@ sonarqube { "**/TestingSupportController.java" property "sonar.projectName", "ccd-data-store-api" property "sonar.projectKey", "ccd-data-store-api" + property "sonar.organization", System.getenv("SONAR_ORGANIZATION") ?: "hmcts" property "sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/reports/jacoco/test/jacocoTestReport.xml" } } From cff6f8ee40b4385129dbdc638a019420a5e8a19d Mon Sep 17 00:00:00 2001 From: Dinesh Patel Date: Thu, 26 Feb 2026 13:50:27 +0000 Subject: [PATCH 4/5] update config --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 7b4c400094..bb3bf0c934 100644 --- a/build.gradle +++ b/build.gradle @@ -565,6 +565,7 @@ sonarqube { property "sonar.exclusions", "build/generated-sources/**/*.java," + "**/AppInsightsConfiguration.java," + "**/TestingSupportController.java" + property "sonar.host.url", "https://sonarcloud.io" property "sonar.projectName", "ccd-data-store-api" property "sonar.projectKey", "ccd-data-store-api" property "sonar.organization", System.getenv("SONAR_ORGANIZATION") ?: "hmcts" From 8b646d37cb485d4523f89ef5fc258c332291ffa6 Mon Sep 17 00:00:00 2001 From: Dinesh Patel Date: Thu, 26 Feb 2026 14:04:51 +0000 Subject: [PATCH 5/5] config changes --- build.gradle | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index bb3bf0c934..9472a2c1e6 100644 --- a/build.gradle +++ b/build.gradle @@ -562,13 +562,20 @@ jsonSchema2Pojo { sonarqube { properties { + def sonarProjectKey = System.getenv("SONAR_PROJECT_KEY") ?: "ccd-data-store-api" + def sonarOrganization = System.getenv("SONAR_ORGANIZATION") ?: "hmcts" + def sonarToken = System.getenv("SONAR_TOKEN") ?: System.getenv("SONAR_AUTH_TOKEN") + property "sonar.exclusions", "build/generated-sources/**/*.java," + "**/AppInsightsConfiguration.java," + "**/TestingSupportController.java" property "sonar.host.url", "https://sonarcloud.io" property "sonar.projectName", "ccd-data-store-api" - property "sonar.projectKey", "ccd-data-store-api" - property "sonar.organization", System.getenv("SONAR_ORGANIZATION") ?: "hmcts" + property "sonar.projectKey", sonarProjectKey + property "sonar.organization", sonarOrganization + if (sonarToken) { + property "sonar.token", sonarToken + } property "sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/reports/jacoco/test/jacocoTestReport.xml" } }