GEODE-3423: Have Gradle set LOCAL_USER_ID - This is needed because Jenkins' Gradle job doesn't seem to provide the ability to pass environment variables in.
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/d295876d Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/d295876d Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/d295876d Branch: refs/heads/feature/GEODE-1279 Commit: d295876d601300e52515193efcf5fd8549f10dbb Parents: a600068 Author: Jens Deppe <[email protected]> Authored: Tue Aug 15 07:57:00 2017 -0700 Committer: Jens Deppe <[email protected]> Committed: Tue Aug 15 07:57:00 2017 -0700 ---------------------------------------------------------------------- gradle/docker.gradle | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/d295876d/gradle/docker.gradle ---------------------------------------------------------------------- diff --git a/gradle/docker.gradle b/gradle/docker.gradle index d4828e4..b5a356f 100644 --- a/gradle/docker.gradle +++ b/gradle/docker.gradle @@ -38,6 +38,17 @@ * The default is 'root'. */ +static def getWorkingDirArgIndex(args) { + def index = 0 + for (arg in args) { + if (arg.equals('-w')) { + return index + 1 + } + index++ + } + return -1 +} + def dockerConfig = { maxParallelForks = dunitParallelForks.toInteger() @@ -76,17 +87,32 @@ def dockerConfig = { } // Remove JAVA_HOME and PATH env variables - they might not be the same as the container needs - args[javaHomeIdx] = 'JAVA_HOME_REMOVED=' - args[pathIdx] = 'PATH_REMOVED=' + if (javaHomeIdx > 0) { + args[javaHomeIdx] = 'JAVA_HOME_REMOVED=' + } + if (pathIdx > 0) { + args[pathIdx] = 'PATH_REMOVED=' + } + + // Unfortunately this snippet of code is here and is required by dev-tools/docker/base/entrypoint.sh. + // This allows preserving the outer user inside the running container. Required for Jenkins + // and other environments. There doesn't seem to be a way to pass this environment variable + // in from a Jenkins Gradle job. + if (System.env['LOCAL_USER_ID'] == null) { + def username = System.getProperty("user.name") + def uid = ['id', '-u', username].execute().text.trim() + args.add(1, "-e" as String) + args.add(2, "LOCAL_USER_ID=${uid}" as String) + } // Infer the index of this invocation def matcher = (args[args.size - 1] =~ /.*Executor (\d*).*/) - args[3] = args[3] + matcher[0][1] - def workdir = new File(args[3]) - // println "dockerize: making ${workdir}" + def pwdIndex = getWorkingDirArgIndex(args) + args[pwdIndex] = args[pwdIndex] + matcher[0][1] + def workdir = new File(args[pwdIndex]) workdir.mkdirs() - // println args +// println args args }
