Must-share information (formatted with Markdown):
- SonarQube 9.2
- We are trying to enable PR decoration for Git repository. We are doing the sonar-scan with Jenkins pipeline. Following this document - GitHub Integration | SonarQube Docs
- what have you tried so far to achieve this
We tried to run the scan manually and it’s working fine but when we are trying to do it with Jenkins it’s not working. Since we have created the project manually, we have also tried adding parameters mentioned in this document - SonarQube
This is our jenkins pipeline stage:
stage('SonarQube Analysis') {
container('jdk') {
// Define sonarqube analysis parameters
def sonarParams = ""
def scannerHome = tool 'SonarScanner';
if (env.CHANGE_ID) {
sonarParams = "-Dsonar.pullrequest.key=${env.CHANGE_ID}"
sonarParams += " -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}"
sonarParams += " -Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
} else {
sonarParams = "-Dsonar.branch.name=${env.BRANCH_NAME}"
}
withSonarQubeEnv() {
sh "${scannerHome}/bin/sonar-scanner ${sonarParams}"
}
}
}
The values of Env variables are not rendering during the scan but when we specify the hard code values it works fine. Could you please suggest what if these are the correct environment variables ?
Since we are using a multi branch pipeline so can’t hard code the parameter values.