Skip to content

Commit 9a039e6

Browse files
committed
NO-JIRA: Report to Sonar correctly for both branch and PR builds.
1 parent e9d4451 commit 9a039e6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

CI.Jenkinsfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ node ("docker-light") {
99
}
1010
stage("Maven Build") {
1111
withSonarQubeEnv {
12+
mySonarOpts="-Dsonar.login=${env.SONAR_AUTH_TOKEN} -Dsonar.host.url=${env.SONAR_HOST_URL}"
13+
if ("${env.CHANGE_BRANCH}") {
14+
mySonarOpts="$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}"
15+
}
16+
echo("Sonar Options are: $mySonarOpts")
1217
sh "docker run --rm \
1318
--pull always \
1419
--volume ${sourceDir}:/source \
@@ -17,12 +22,7 @@ node ("docker-light") {
1722
bash -c \"apt-get update && \
1823
apt-get install -y git && \
1924
pushd /source && \
20-
export MY_SONAR_OPTS=\"-Dsonar.login=${env.SONAR_AUTH_TOKEN} -Dsonar.host.url=${env.SONAR_HOST_URL}\" \
21-
if [[ ! -z ${env.CHANGE_BRANCH} ]]; then \
22-
MY_SONAR_OPTS+=-Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
23-
fi \
24-
echo \"Sonar Options are: ${env.MY_SONAR_OPTS}\" \
25-
/opt/maven-basis/bin/mvn --batch-mode clean install sonar:sonar ${MY_SONAR_OPTS}\""
25+
/opt/maven-basis/bin/mvn --batch-mode clean install sonar:sonar $mySonarOpts\""
2626
}
2727
}
2828
slack(true)

0 commit comments

Comments
 (0)