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 {