From a8ed8db95021e988540f02543d3099fe97d86dba Mon Sep 17 00:00:00 2001 From: Caleb Reder Date: Mon, 13 Sep 2021 10:44:30 -0500 Subject: [PATCH] =?UTF-8?q?Removing=20always=20disabling=20the=20gradle-da?= =?UTF-8?q?emon=20per=20https://docs.gradle.o=E2=80=A6=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Removing always disabling the gradle-daemon per https://docs.gradle.org/current/userguide/gradle_daemon.html#sec:disabling_the_daemon * Adding in JENKINS_NODE_COOKIE='dontKillMe' so we dont kill gradle daemons * Adding Jenkins node variable to batch calls also Co-authored-by: Caleb Reder --- ...with-custom-configurable-dsl-components.md | 7 +++-- .../dsl/step/custom/GradleBuildDsl.kt | 14 ++++++--- .../src/generated/ci/gradleBuild.Jenkinsfile | 30 +++++++++++-------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/docs/extending-with-custom-configurable-dsl-components.md b/docs/extending-with-custom-configurable-dsl-components.md index 58619922..fa9143e6 100644 --- a/docs/extending-with-custom-configurable-dsl-components.md +++ b/docs/extending-with-custom-configurable-dsl-components.md @@ -71,8 +71,11 @@ data class GradleBuildDsl( ) { ... fun DslContext.gradleCommand(command: String, additionalBuildArgs: Var.Literal.Str) = - withEnv(mapOf("GRADLE_USER_HOME" to "${"WORKSPACE".environmentVar()}/.gradle-home-tmp")) { artifactoryAuthenticated { - sh(("./gradlew --no-daemon --stacktrace --build-cache " + + withEnv( + mapOf("GRADLE_USER_HOME" to "${"WORKSPACE".environmentVar()}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE" to "dontKillMe") + ) { artifactoryAuthenticated { + sh(("./gradlew --stacktrace --build-cache " + (gradleCredentials?.let { "-D$gradleUserProperty=\\\"\\\${${it.usernameVariable.value}}\\\" -D$gradlePasswordProperty=\\\"\\\${${it.passwordVariable.value}}\\\" " } ?: "") + "$additionalBuildArgs $command").strDouble()) } } diff --git a/dsl/src/main/kotlin/com/code42/jenkins/pipelinekt/dsl/step/custom/GradleBuildDsl.kt b/dsl/src/main/kotlin/com/code42/jenkins/pipelinekt/dsl/step/custom/GradleBuildDsl.kt index 91528b68..d962bd46 100644 --- a/dsl/src/main/kotlin/com/code42/jenkins/pipelinekt/dsl/step/custom/GradleBuildDsl.kt +++ b/dsl/src/main/kotlin/com/code42/jenkins/pipelinekt/dsl/step/custom/GradleBuildDsl.kt @@ -45,15 +45,21 @@ data class GradleBuildDsl( this.gradleCommandBat(command, additionalBuildArgs.strDouble()) fun DslContext.gradleCommandSh(command: String, additionalBuildArgs: Var.Literal.Str) = - withEnv(mapOf("GRADLE_USER_HOME" to "${"WORKSPACE".environmentVar()}/.gradle-home-tmp")) { artifactoryAuthenticated { - sh(("./gradlew --no-daemon --stacktrace --build-cache " + + withEnv( + mapOf("GRADLE_USER_HOME" to "${"WORKSPACE".environmentVar()}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE" to "dontKillMe") + ) { artifactoryAuthenticated { + sh(("./gradlew --stacktrace --build-cache " + (gradleCredentials?.let { "-D$gradleUserProperty=\\\"\\\${${it.usernameVariable.value}}\\\" -D$gradlePasswordProperty=\\\"\\\${${it.passwordVariable.value}}\\\" " } ?: "") + "$additionalBuildArgs $command").strDouble()) } } fun DslContext.gradleCommandBat(command: String, additionalBuildArgs: Var.Literal.Str) = - withEnv(mapOf("GRADLE_USER_HOME" to "${"WORKSPACE".environmentVar()}/.gradle-home-tmp")) { artifactoryAuthenticated { - bat(("call gradlew.bat --no-daemon --stacktrace --build-cache " + + withEnv( + mapOf("GRADLE_USER_HOME" to "${"WORKSPACE".environmentVar()}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE" to "dontKillMe") + ) { artifactoryAuthenticated { + bat(("call gradlew.bat --stacktrace --build-cache " + (gradleCredentials?.let { "-D$gradleUserProperty=%${it.usernameVariable.value}% -D$gradlePasswordProperty=%${it.passwordVariable.value}% " } ?: "") + "$additionalBuildArgs $command").strDouble()) } } diff --git a/examples/src/generated/ci/gradleBuild.Jenkinsfile b/examples/src/generated/ci/gradleBuild.Jenkinsfile index 0c80e135..a32b2088 100644 --- a/examples/src/generated/ci/gradleBuild.Jenkinsfile +++ b/examples/src/generated/ci/gradleBuild.Jenkinsfile @@ -1,43 +1,49 @@ def Build() { withEnv([ - "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp" + "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE=dontKillMe" ]) { - sh (script: "./gradlew --no-daemon --stacktrace --build-cache ${""} build -DmyArg=myArgValue", returnStdout: false) + sh (script: "./gradlew --stacktrace --build-cache ${""} build -DmyArg=myArgValue", returnStdout: false) } } def api_Test() { withEnv([ - "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp" + "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE=dontKillMe" ]) { - sh (script: "./gradlew --no-daemon --stacktrace --build-cache ${""} :api:systemTest -DmyArg=myArgValue", returnStdout: false) + sh (script: "./gradlew --stacktrace --build-cache ${""} :api:systemTest -DmyArg=myArgValue", returnStdout: false) } } def ext_Test() { withEnv([ - "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp" + "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE=dontKillMe" ]) { - sh (script: "./gradlew --no-daemon --stacktrace --build-cache ${""} :ext:systemTest -DmyArg=myArgValue", returnStdout: false) + sh (script: "./gradlew --stacktrace --build-cache ${""} :ext:systemTest -DmyArg=myArgValue", returnStdout: false) } } def shared_Test() { withEnv([ - "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp" + "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE=dontKillMe" ]) { - sh (script: "./gradlew --no-daemon --stacktrace --build-cache ${""} :shared:systemTest -DmyArg=myArgValue", returnStdout: false) + sh (script: "./gradlew --stacktrace --build-cache ${""} :shared:systemTest -DmyArg=myArgValue", returnStdout: false) } } def mod1_Test() { withEnv([ - "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp" + "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE=dontKillMe" ]) { - sh (script: "./gradlew --no-daemon --stacktrace --build-cache ${""} :mod1:systemTest -DmyArg=myArgValue", returnStdout: false) + sh (script: "./gradlew --stacktrace --build-cache ${""} :mod1:systemTest -DmyArg=myArgValue", returnStdout: false) } } def Publish() { withEnv([ - "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp" + "GRADLE_USER_HOME=${env.WORKSPACE}/.gradle-home-tmp", + "JENKINS_NODE_COOKIE=dontKillMe" ]) { - sh (script: "./gradlew --no-daemon --stacktrace --build-cache ${""} publish -DmyArg=myArgValue", returnStdout: false) + sh (script: "./gradlew --stacktrace --build-cache ${""} publish -DmyArg=myArgValue", returnStdout: false) } } pipeline {