From eda82df3356ba58e0d3d7a6b470062b1659643fc Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Fri, 4 Sep 2026 12:18:38 -0400 Subject: [PATCH 1/2] Reuse Gradle plugin cache in nightly builds --- .gitlab-ci.yml | 66 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index df0fca12659..22015543db9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -219,7 +219,8 @@ default: GIT_SUBMODULE_STRATEGY: normal GIT_SUBMODULE_DEPTH: 1 cache: - - key: dependency-$CACHE_TYPE # Dependencies cache + - &dependency_cache + key: dependency-$CACHE_TYPE # Dependencies cache paths: # Cached dependencies and wrappers for Gradle and Maven: - .gradle/wrapper @@ -231,7 +232,8 @@ default: fallback_keys: # Use fallback keys because all cache types are not populated. See note under: populate_dep_cache - 'dependency-base' - 'dependency-lib' - - key: $CI_PIPELINE_ID-$CACHE_TYPE # Incremental build cache. Shared by all jobs in the pipeline of the same type + - &build_cache + key: $CI_PIPELINE_ID-$CACHE_TYPE # Incremental build cache. Shared by all jobs in the pipeline of the same type paths: - .gradle/caches/$GRADLE_VERSION - .gradle/$GRADLE_VERSION/executionHistory @@ -389,14 +391,74 @@ build_tests: - ./gradlew --version - ./gradlew clean $GRADLE_TARGET $GRADLE_PARAMS -PskipTests $GRADLE_ARGS +populate_plugin_cache: + extends: .gradle_build + cache: + - &plugin_cache + key: dependency-plugins-$GRADLE_VERSION + paths: + - .gradle-plugin-cache/caches/modules-2 + policy: pull-push + when: always + unprotect: true + rules: + - if: '$POPULATE_CACHE' + when: on_success + script: + - mkdir -p .gradle-plugin-cache + - sudo chown -R 1001:1001 .gradle-plugin-cache + - export GRADLE_USER_HOME=$(pwd)/.gradle-plugin-cache + - | + plugin_cache_log=plugin-cache-population.log + set +e + ./gradlew help -PskipTests $GRADLE_ARGS 2>&1 | tee "$plugin_cache_log" + gradle_status=${PIPESTATUS[0]} + set -e + + if [ "$gradle_status" -eq 0 ]; then + echo "PLUGIN_CACHE_MAVEN_CENTRAL_429=false" + echo "Plugin cache population completed successfully." + elif grep -Eq 'https://repo\.maven\.apache\.org/|https://repo1\.maven\.org/' "$plugin_cache_log" && + grep -Eq 'Received status code 429|Too Many Requests' "$plugin_cache_log"; then + rate_limit_count=$(grep -Ec 'Received status code 429|Too Many Requests' "$plugin_cache_log" || true) + echo "PLUGIN_CACHE_MAVEN_CENTRAL_429=true count=$rate_limit_count" + echo "WARNING: Maven Central rate limiting interrupted plugin cache population." + echo "Keeping the partially populated cache so the next nightly run can resume from it." + else + echo "PLUGIN_CACHE_MAVEN_CENTRAL_429=false" + echo "ERROR: Plugin cache population failed without a Maven Central 429 (Gradle exit $gradle_status)." + exit "$gradle_status" + fi + retry: + max: 2 + when: script_failure + populate_dep_cache: extends: build_tests + # Wait for build-cache producers so their caches are uploaded before this job restores them. + needs: + - job: populate_plugin_cache + - job: build + artifacts: false + - job: build_tests + artifacts: false variables: BUILD_CACHE_POLICY: pull DEPENDENCY_CACHE_POLICY: push + cache: + - <<: *plugin_cache + policy: pull + - *dependency_cache + - *build_cache rules: - if: '$POPULATE_CACHE' when: on_success + before_script: + - !reference [.gradle_build, before_script] + - sudo chown -R 1001:1001 .gradle-plugin-cache + # Seed the otherwise cold writable cache, keeping the cache uploaded below self-contained. + - mkdir -p .gradle/caches + - cp -a .gradle-plugin-cache/caches/modules-2 .gradle/caches/ parallel: matrix: - GRADLE_TARGET: ":dd-java-agent:shadowJar :dd-trace-api:jar :dd-trace-ot:shadowJar" From 5c456f5da41fe145ecaffccde88d069a0f3f4fa0 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Fri, 4 Sep 2026 13:57:39 -0400 Subject: [PATCH 2/2] Tolerate unavailable Gradle plugin cache. --- .gitlab-ci.yml | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 22015543db9..73e2e38d3a3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -395,7 +395,7 @@ populate_plugin_cache: extends: .gradle_build cache: - &plugin_cache - key: dependency-plugins-$GRADLE_VERSION + key: dependency-plugins-v1 paths: - .gradle-plugin-cache/caches/modules-2 policy: pull-push @@ -409,29 +409,15 @@ populate_plugin_cache: - sudo chown -R 1001:1001 .gradle-plugin-cache - export GRADLE_USER_HOME=$(pwd)/.gradle-plugin-cache - | - plugin_cache_log=plugin-cache-population.log - set +e - ./gradlew help -PskipTests $GRADLE_ARGS 2>&1 | tee "$plugin_cache_log" - gradle_status=${PIPESTATUS[0]} - set -e - - if [ "$gradle_status" -eq 0 ]; then - echo "PLUGIN_CACHE_MAVEN_CENTRAL_429=false" - echo "Plugin cache population completed successfully." - elif grep -Eq 'https://repo\.maven\.apache\.org/|https://repo1\.maven\.org/' "$plugin_cache_log" && - grep -Eq 'Received status code 429|Too Many Requests' "$plugin_cache_log"; then - rate_limit_count=$(grep -Ec 'Received status code 429|Too Many Requests' "$plugin_cache_log" || true) - echo "PLUGIN_CACHE_MAVEN_CENTRAL_429=true count=$rate_limit_count" - echo "WARNING: Maven Central rate limiting interrupted plugin cache population." - echo "Keeping the partially populated cache so the next nightly run can resume from it." - else - echo "PLUGIN_CACHE_MAVEN_CENTRAL_429=false" - echo "ERROR: Plugin cache population failed without a Maven Central 429 (Gradle exit $gradle_status)." - exit "$gradle_status" + gradle_status=0 + ./gradlew help -PskipTests $GRADLE_ARGS || gradle_status=$? + if ! find .gradle-plugin-cache/caches/modules-2/files-2.1 -type f -print -quit 2>/dev/null | grep -q .; then + echo "WARNING: No plugin artifacts were cached; skipping the cache upload." + rm -rf .gradle-plugin-cache/caches/modules-2 fi - retry: - max: 2 - when: script_failure + exit "$gradle_status" + # This cache warmer is an optimization; population jobs can continue with a cold plugin cache. + allow_failure: true populate_dep_cache: extends: build_tests @@ -455,10 +441,15 @@ populate_dep_cache: when: on_success before_script: - !reference [.gradle_build, before_script] - - sudo chown -R 1001:1001 .gradle-plugin-cache # Seed the otherwise cold writable cache, keeping the cache uploaded below self-contained. - mkdir -p .gradle/caches - - cp -a .gradle-plugin-cache/caches/modules-2 .gradle/caches/ + - | + if [ -d .gradle-plugin-cache/caches/modules-2 ]; then + sudo chown -R 1001:1001 .gradle-plugin-cache + cp -a .gradle-plugin-cache/caches/modules-2 .gradle/caches/ + else + echo "Plugin cache is unavailable; continuing with a cold dependency cache." + fi parallel: matrix: - GRADLE_TARGET: ":dd-java-agent:shadowJar :dd-trace-api:jar :dd-trace-ot:shadowJar"