From deef0d9117406460bd1ee25bb2c01d7dd6405154 Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Wed, 18 Sep 2019 11:51:44 -0700 Subject: [PATCH] Disable bwc distribution caching in master branch (#46686) This commit disables caching of BWC snapshot distributions in the "trunk" (aka master) branch. Since the previous major release branches move quickly we rarely get cache hits for these tasks, and the artifacts themselves are very large. This means the overhead here is high and savings basically zero. We conditionally disable task output caching in this scenario in CI to avoid excessive build cache overhead as well as causing too much turn in the cache itself which would lead to lots of cache entry evictions. --- .../elasticsearch/gradle/info/GlobalBuildInfoPlugin.java | 1 + distribution/bwc/build.gradle | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java index d97f5fb2cd320..b59d9806a0bf4 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java @@ -95,6 +95,7 @@ public void apply(Project project) { ext.set("gradleJavaVersion", Jvm.current().getJavaVersion()); ext.set("gitRevision", gitRevision(project.getRootProject().getRootDir())); ext.set("buildDate", ZonedDateTime.now(ZoneOffset.UTC)); + ext.set("isCi", System.getenv("JENKINS_URL") != null); }); } diff --git a/distribution/bwc/build.gradle b/distribution/bwc/build.gradle index 3c41314af5a49..3642efa7746e4 100644 --- a/distribution/bwc/build.gradle +++ b/distribution/bwc/build.gradle @@ -223,8 +223,14 @@ bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInfo unreleased Task bwcTask = createRunBwcGradleTask(buildBwcTaskName(projectName)) { inputs.file("${project.buildDir}/refspec") outputs.files(projectArtifact) - outputs.cacheIf { true } + outputs.cacheIf("BWC distribution caching is disabled on 'master' branch") { + // Don't bother caching in 'master' since the BWC branches move too quickly to make this cost worthwhile + project.ext.isCi && System.getenv('GIT_BRANCH')?.endsWith("master") == false + } args ":${projectDir.replace('/', ':')}:assemble" + if (project.gradle.startParameter.buildCacheEnabled) { + args "--build-cache" + } doLast { if (projectArtifact.exists() == false) { throw new InvalidUserDataException("Building ${bwcVersion} didn't generate expected file ${projectArtifact}")