diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 992e3034..1e07d557 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -76,8 +76,7 @@ variables: - bundle -v || gem install bundler --source https://gems.ruby-china.com/ - ls -li - export NEXT_VERSION="$(cat app_new.version)" - - bundle config set --local path 'vendor/bundle_android' # Android独立依赖目录 - - bundle install --gemfile android/Gemfile # 去掉--quiet,便于观察进度 + - bash scripts/bundle_install_retry.sh android/Gemfile vendor/bundle_android - gem pristine --all || true # 修复所有未编译的gem扩展 script: # 输出调试信息,便于后续排查环境问题 @@ -108,8 +107,7 @@ variables: - bundle -v || gem install bundler --source https://gems.ruby-china.com/ - ls -li - export NEXT_VERSION="$(cat app_new.version)" - - bundle config set --local path 'vendor/bundle_ios' # iOS独立依赖目录 - - bundle install --gemfile ios/Gemfile # 去掉--quiet,便于观察进度 + - bash scripts/bundle_install_retry.sh ios/Gemfile vendor/bundle_ios - gem pristine --all || true # 修复所有未编译的gem扩展 script: # 输出调试信息,便于后续排查环境问题 diff --git a/scripts/bundle_install_retry.sh b/scripts/bundle_install_retry.sh new file mode 100644 index 00000000..2678b221 --- /dev/null +++ b/scripts/bundle_install_retry.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# 用法: ./scripts/bundle_install_retry.sh +# 例如: ./scripts/bundle_install_retry.sh android/Gemfile vendor/bundle_android + +GEMFILE_PATH="$1" +BUNDLE_PATH="$2" + +if [ -z "$GEMFILE_PATH" ] || [ -z "$BUNDLE_PATH" ]; then + echo "用法: $0 " + exit 1 +fi + +try_count=0 +max_try=3 +success=0 + +# 先用阿里云镜像 +bundle config mirror.https://rubygems.org https://mirrors.aliyun.com/rubygems/ +while [ $try_count -lt $max_try ]; do + echo "[INFO] 第$((try_count+1))次尝试使用阿里云镜像 bundle install..." + bundle config set --local path "$BUNDLE_PATH" + bundle install --gemfile "$GEMFILE_PATH" + if [ $? -eq 0 ]; then + echo "[SUCCESS] 使用阿里云镜像 bundle install 成功" + success=1 + break + fi + try_count=$((try_count+1)) + sleep 2 + echo "[WARN] 阿里云镜像 bundle install 第$try_count 次失败,准备重试..." +done + +if [ $success -eq 0 ]; then + echo "[ERROR] 阿里云镜像 bundle install 失败$max_try次,切换为官方源重试..." + bundle config mirror.https://rubygems.org https://rubygems.org + bundle config set --local path "$BUNDLE_PATH" + bundle install --gemfile "$GEMFILE_PATH" + if [ $? -eq 0 ]; then + echo "[SUCCESS] 官方源 bundle install 成功" + exit 0 + else + echo "[FATAL] 官方源 bundle install 依然失败,请检查网络或Gemfile配置。" + exit 2 + fi +fi +exit 0 \ No newline at end of file