- ALM used (GitHub)
- CI system used (Jenkins) Multibranch Pipeline
The main question is how do I configure it so that I can update master branch and PR with decorations.
I seem to be able to do one or the other but not both, when using a multi-branch pipeline.
My config is below :
sonar.organization=insightcapital
sonar.projectKey=test
sonar.projectName=Test Project
sonar.projectVersion=1.0
# Language
sonar.language=py
# Encoding of the source files
sonar.sourceEncoding=UTF-8
# Source code
sonar.sources=./myproj/
sonar.exclusions=myproj/static/vendors/**
# Unit tests
sonar.python.xunit.reportPath=results.xml
sonar.python.coverage.reportPaths=reports/cobertura.xml
# Unit tests
sonar.tests=./tests/
sonar.loglevel=DEBUG
sonar.showProfiling=true
sonar.pullrequest.base=master
sonar.pullrequest.provider=github
sonar.pullrequest.github.repository=test/test
In my jenkins pipeline I have
stage('SonarQube analysis - Master') {
when { branch 'master' }
steps {
withSonarQubeEnv('SonarQubeCloud') {
sh"""
sonar-scanner sonar.branch.name=master
"""
}
}
}
stage('SonarQube analysis - PR') {
when { not { anyOf { branch 'master' }}}
steps {
withSonarQubeEnv('SonarQubeCloud') {
sh"""
sonar-scanner -D sonar.pullrequest.branch=${env.BRANCH_NAME} -D sonar.pullrequest.key=${env.CHANGE_ID}
"""
}
}
}
I’ve tried various options in the master section
/bin/bash -c "sonar-scanner" "-D" "sonar.branch.name=master"
gives me
"A pull request analysis cannot have the branch analysis parameter 'sonar.branch.name'"
running
/bin/bash -c "sonar-scanner"
gives me
"Parameter 'sonar.pullrequest.key' is mandatory for a pull request analysis"
running
/bin/bash -c "sonar-scanner" "-D" "sonar.pullrequest.branch=master" "-D" "sonar.pullrequest.key=null"
creates a weird PR, and doesn’t update the master branch.