- ALM used - GitHub
- CI system used - Jenkins
- Language of the repository - Java project with Maven
The process I followed for adding my project to Sonarcloud -
- Let it get discovered by the GitHub integration
- Uncheck “Automatic Analysis” from the Administration → Analysis Method page for the project on SonarCloud
- Modified the long-lived branch regex to “(develop|master)”
- Configure the SonarCloud under Jenkins → Manage Jenkins → SonarQube servers
- Configured my SonarScanner under Jenkins → Manage Jenkins → Tools → SonarQube scanner
- Run analysis from my scripted pipeline with below code
if ("true".equalsIgnoreCase("${run_test}") && "true".equalsIgnoreCase("${run_sonar_analysis}")) {
def projectKeySC = "<proj-key>"
def githubOrg = "<org-name>"
SonarQube_analysis("${projectKeySC}", "${githubOrg}")
timeout(time: 1, unit: 'HOURS') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
/ true = set pipeline to UNSTABLE, false = don't
waitForQualityGate abortPipeline: true
}
}
....
....
....
//function
def SonarQube_analysis(String projKey, String githubOrg) {
def scannerHome = tool '<name of SonarScanner tool>'
withSonarQubeEnv('SonarCloud') {
if (env.CHANGE_ID != null) {
sh "mvn -B sonar:sonar \
-Dsonar.projectKey=${projKey} \
-Dsonar.pullrequest.provider=GitHub \
-Dsonar.pullrequest.github.repository=${githubOrg}/${repo} \
-Dsonar.pullrequest.key=${env.CHANGE_ID} \
-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
-Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
} else {
if ("develop".equals(env.BRANCH_NAME)) {
sh "mvn -B sonar:sonar \
-Dsonar.projectKey=${projKey} \
-Dsonar.branch.name=${env.BRANCH_NAME}"
} else {
sh "mvn -B sonar:sonar \
- Dsonar.projectKey=${projKey} \
-Dsonar.branch.name=${env.BRANCH_NAME} \
-Dsonar.branch.target=main"
}
}
}
}
Issue - My branch analysis succeeds and QG status is reported back to Jenkins. PR analysis also succeeds and QG status is reported back to Jenkins. But the main (“develop”) branch analysis succeeds but QG status is not reported back to Jenkins
Please help. I have been stuck with this issue since last two days
Thanks