Skip to content

Commit

Permalink
Syntax fix 3
Browse files Browse the repository at this point in the history
  • Loading branch information
asolimando committed Jul 26, 2024
1 parent 43f0996 commit 9e79be3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,33 @@ node('ubuntu') {
timeout(time: 1, unit: 'HOURS') {
withEnv(["Path+JDK=$JAVA_JDK_17/bin","JAVA_HOME=$JAVA_JDK_17"]) {
def JVM_ARGS = "-XX:+UseG1GC -Xmx1536m -XX:MaxMetaspaceSize=512m"
// SONAR_TOKEN is a secret and can't be interpolated in a Groovy string for security measures,
// see https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#interpolation-of-sensitive-environment-variables
def COMMON_ARGS = """
build --no-parallel --no-daemon jacocoAggregateTestReport \
sonar -PenableJacoco -Porg.sonarqube.version=4.4.1.3373 \
-Dorg.gradle.jvmargs='${JVM_ARGS}' \
-Dsonar.token=\$SONAR_TOKEN \
""".trim()
def FULL_COMMAND

withCredentials([string(credentialsId: 'SONARCLOUD_TOKEN', variable: 'SONAR_TOKEN')]) {
if (env.BRANCH_NAME.startsWith("PR-")) {
def PR_ARGS = """
-Dsonar.pullrequest.branch=${CHANGE_BRANCH} \
-Dsonar.pullrequest.base=${CHANGE_TARGET} \
-Dsonar.pullrequest.key=${CHANGE_ID} \
""".trim()
sh "./gradlew ${COMMON_ARGS} ${PR_ARGS} -Dsonar.token=${SONAR_TOKEN}"
FULL_COMMAND = "./gradlew ${COMMON_ARGS} ${PR_ARGS}"
} else {
sh "./gradlew ${COMMON_ARGS} -Dsonar.branch.name=${BRANCH_NAME} -Dsonar.token=${SONAR_TOKEN}"
FULL_COMMAND = "./gradlew ${COMMON_ARGS} -Dsonar.branch.name=${BRANCH_NAME}"
}
}

// to avoid problems with Groovy's interpolation for secrets
withEnv(["SONAR_TOKEN=${SONAR_TOKEN}"]) {
sh """
./gradlew ${FULL_COMMAND}
"""
}
}
}
}
Expand Down

0 comments on commit 9e79be3

Please sign in to comment.