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
This commit is contained in:
YuanXuan 2026-03-24 11:14:13 +08:00
parent 9fbefc4438
commit 55d035cb9c
1 changed files with 17 additions and 7 deletions

24
Jenkinsfile vendored
View File

@ -159,13 +159,23 @@ pipeline {
echo " - 开始构建 APK 参数: \$EXTRA_ARGS" echo " - 开始构建 APK 参数: \$EXTRA_ARGS"
echo " - 开始执行 flutter build apk构建期间每30秒输出一次心跳..." echo " - 开始执行 flutter build apk构建期间每30秒输出一次心跳..."
(fvm flutter build apk --release \$EXTRA_ARGS) &
BUILD_PID=\$! run_build_with_heartbeat() {
while kill -0 \$BUILD_PID 2>/dev/null; do (fvm flutter build apk --release \$EXTRA_ARGS) &
echo " - 构建仍在进行中... \$(date '+%H:%M:%S')" BUILD_PID=\$!
sleep 30 while kill -0 \$BUILD_PID 2>/dev/null; do
done echo " - 构建仍在进行中... \$(date '+%H:%M:%S')"
wait \$BUILD_PID 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 构建完成" echo " ✅ ${currentApp} Android APK 构建完成"
} }