Skip to content

Commit

Permalink
Syntax fix 5
Browse files Browse the repository at this point in the history
  • Loading branch information
asolimando committed Jul 26, 2024
1 parent 3ddec92 commit f68ded0
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,21 @@ node('ubuntu') {
""".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()
FULL_COMMAND = "./gradlew ${COMMON_ARGS} ${PR_ARGS}"
} else {
FULL_COMMAND = "./gradlew ${COMMON_ARGS} -Dsonar.branch.name=${BRANCH_NAME}"
}
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()
FULL_COMMAND = "./gradlew ${COMMON_ARGS} ${PR_ARGS}"
} else {
FULL_COMMAND = "./gradlew ${COMMON_ARGS} -Dsonar.branch.name=${BRANCH_NAME}"
}

// to avoid problems with Groovy's interpolation for secrets
withEnv(["SONAR_TOKEN=${SONAR_TOKEN}"]) {
withCredentials([string(credentialsId: 'SONARCLOUD_TOKEN', variable: 'SONAR_TOKEN')]) {
sh """
./gradlew ${FULL_COMMAND} -Dsonar.token=\$SONAR_TOKEN
./gradlew ${FULL_COMMAND} -Dsonar.token=${SONAR_TOKEN}
"""
}
}
Expand Down

0 comments on commit f68ded0

Please sign in to comment.