Skip to content

Commit

Permalink
Removing always disabling the gradle-daemon per https://docs.gradle.o… (
Browse files Browse the repository at this point in the history
#27)

* 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 <[email protected]>
  • Loading branch information
reder9 and Caleb Reder authored Sep 13, 2021
1 parent a711a0a commit a8ed8db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
7 changes: 5 additions & 2 deletions docs/extending-with-custom-configurable-dsl-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ data class GradleBuildDsl(
) {
...
fun DslContext<Step>.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())
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,21 @@ data class GradleBuildDsl(
this.gradleCommandBat(command, additionalBuildArgs.strDouble())

fun DslContext<Step>.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<Step>.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())
} }
Expand Down
30 changes: 18 additions & 12 deletions examples/src/generated/ci/gradleBuild.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit a8ed8db

Please sign in to comment.