diff --git a/Jenkinsfile b/Jenkinsfile index 4ddf59d18149..da57196d8878 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,22 +42,21 @@ node('ubuntu') { stage('Code Quality') { 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}' \ + """.trim() withCredentials([string(credentialsId: 'SONARCLOUD_TOKEN', variable: 'SONAR_TOKEN')]) { - 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}' \ - """ - 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}" } else { sh "./gradlew ${COMMON_ARGS} -Dsonar.branch.name=${BRANCH_NAME} -Dsonar.token=${SONAR_TOKEN}"