Hello everyone,
SonarQube Version: Version 8.9.10
sonarqube-scanner Version: 2.8.2
Jenkins Version: 2.361.2
I’m trying to dynamically change the SonarQube branch name in my CI Pipeline. But it seem like the arguments that I pass to the scanner are ignored. At the Moment all the Scans are published on the default branch.
I have already tried to delete my properties File and set all arguments in the bash. But I get the following error:
ERROR: You must define the following mandatory properties for ‘Unknown’: sonar.projectKey
In my previous maven Project I could set the Branch name dynamically in the Jenkins File. Seems like in NPM it’s not possible to pass arguments to the Scanner. Can anyone help me?
That’s my actual properties File:
sonar.projectKey=*****
sonar.sources= .
sonar.host.url=***
sonar.login=***
sonar.language=js
sonar.javascript.lcov.reportPaths=***
sonar.exclusions=**/*.spec.js, **/*.spec.ts, cypress**, **/*.conf.js, **/*.prod.js
sonar.coverage.exclusions=**/*.spec.ts, **/*module.ts
That’s my actual Jenkins File:
stage('SonarQube analysis') {
steps {
withSonarQubeEnv(credentialsId: '****', installationName: '****') {
echo "name is => ${env.BRANCH_NAME}"
sh 'npm install sonar-scanner'
sh "npm run sonar-scanner -Dsonar.branch.name=${env.BRANCH_NAME}"
}
}
}
When I set the branch.name in the sonar-project.properties File it works. But the name can’t be dynamically changed.