From 55d035cb9cf1cf59535c6974fd0cbcb38f3ca75a Mon Sep 17 00:00:00 2001 From: YuanXuan Date: Tue, 24 Mar 2026 11:14:13 +0800 Subject: [PATCH] fix(ci): retry apk build after clearing corrupted Gradle cache Handle sporadic Gradle wrapper zip corruption on Jenkins by retrying build once after removing ~/.gradle/wrapper/dists. Made-with: Cursor --- Jenkinsfile | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cef1f55..f2b979a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -159,13 +159,23 @@ pipeline { echo " - 开始构建 APK 参数: \$EXTRA_ARGS" echo " - 开始执行 flutter build apk(构建期间每30秒输出一次心跳)..." - (fvm flutter build apk --release \$EXTRA_ARGS) & - BUILD_PID=\$! - while kill -0 \$BUILD_PID 2>/dev/null; do - echo " - 构建仍在进行中... \$(date '+%H:%M:%S')" - sleep 30 - done - wait \$BUILD_PID + + run_build_with_heartbeat() { + (fvm flutter build apk --release \$EXTRA_ARGS) & + BUILD_PID=\$! + while kill -0 \$BUILD_PID 2>/dev/null; do + echo " - 构建仍在进行中... \$(date '+%H:%M:%S')" + sleep 30 + done + wait \$BUILD_PID + return \$? + } + + if ! run_build_with_heartbeat; then + echo " ⚠️ 首次构建失败,尝试清理 Gradle wrapper 缓存后重试一次..." + rm -rf "\$HOME/.gradle/wrapper/dists" + run_build_with_heartbeat + fi """ echo " ✅ ${currentApp} Android APK 构建完成" }