fix(ci): 优化Woodpecker CI配置,增强SSH连接和Git操作可靠性
ci/woodpecker/push/woodpecker Pipeline failed

- 增强SSH连接测试,添加timeout和BatchMode参数
- 改进网络连通性检查,使用dig替代nslookup
- 分步骤执行Git归档操作,每一步都有错误检查
- 增强错误处理和日志输出,便于问题诊断
- 添加CICD配置验证脚本
This commit is contained in:
张翔
2026-03-30 20:59:11 +08:00
parent 4a2d5dc385
commit a4fd907add
2 changed files with 159 additions and 19 deletions
+34 -19
View File
@@ -168,14 +168,14 @@ steps:
depends_on:
- build-and-deploy
commands:
- echo "=== Archiving to main branch (Docker环境) ==="
- echo "=== Archiving to main branch (增强可靠性版本) ==="
- echo "当前容器信息:"
- 'echo "主机名: $(hostname)"'
- 'echo "IP地址: $(hostname -i)"'
- echo ""
- echo ""
- echo "1. 安装必要的工具"
- apk add --no-cache git openssh-client curl
- apk add --no-cache git openssh-client curl bind-tools netcat-openbsd
- echo ""
- echo "2. 配置SSH环境"
- mkdir -p ~/.ssh
@@ -186,18 +186,18 @@ steps:
- 'wc -c < ~/.ssh/id_rsa'
- echo ""
- echo "3. 配置Git服务器主机密钥"
- ssh-keyscan -H git.f.novalon.cn >> ~/.ssh/known_hosts
- ssh-keyscan -H -p 22 git.f.novalon.cn >> ~/.ssh/known_hosts
- echo "✅ Git服务器主机密钥已添加"
- echo ""
- echo "4. 测试网络连接"
- echo "4. 增强网络连接测试"
- echo "测试DNS解析:"
- 'nslookup git.f.novalon.cn || echo "DNS解析测试完成"'
- 'dig +short git.f.novalon.cn || nslookup git.f.novalon.cn || echo "DNS解析测试完成"'
- echo "测试端口连通性:"
- 'nc -zv git.f.novalon.cn 22 && echo "SSH端口可达" || echo "SSH端口不可达"'
- 'timeout 10 nc -zv git.f.novalon.cn 22 && echo "SSH端口可达" || echo "SSH端口不可达"'
- echo ""
- echo "5. 测试SSH连接"
- echo "5. 增强SSH连接测试"
- echo "测试SSH连接到Git服务器..."
- 'ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 -T git@git.f.novalon.cn 2>&1 | head -10 || echo "SSH连接测试完成"'
- 'timeout 15 ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes -T git@git.f.novalon.cn "echo \"✅ SSH连接成功\"" 2>&1 || echo "SSH连接失败,但继续执行"'
- echo ""
- echo "6. 配置Git用户信息"
- git config --global user.email "ci@novalon.cn"
@@ -208,18 +208,33 @@ steps:
- git remote set-url origin git@git.f.novalon.cn:novalon/novalon-website.git
- echo "✅ Git远程仓库已配置"
- echo ""
- echo "8. 测试Git远程访问"
- echo "8. 增强Git远程访问测试"
- echo "测试Git远程仓库访问权限..."
- git ls-remote origin --heads 2>&1 | head -5 || echo "Git远程访问测试完成"
- CURRENT_BRANCH="${CI_COMMIT_BRANCH}"
- echo "Current branch is $CURRENT_BRANCH"
- git checkout main
- git pull origin main
- 'git merge "$CURRENT_BRANCH" --no-ff -m "archive $CURRENT_BRANCH"'
- VERSION_TAG="v$(date +%Y.%m.%d)-${CI_COMMIT_SHA:0:7}"
- 'git tag -a "$VERSION_TAG" -m "Release from $CURRENT_BRANCH"'
- git push origin main && git push origin --tags
- echo "Archive succeeded with version $VERSION_TAG"
- 'timeout 10 git ls-remote origin --heads 2>&1 | head -5 && echo "✅ Git远程访问成功" || echo "Git远程访问失败,但继续执行"'
- echo ""
- echo "9. 执行归档操作(增强错误处理)"
- 'export CURRENT_BRANCH="${CI_COMMIT_BRANCH}"'
- 'echo "当前分支: $CURRENT_BRANCH"'
- 'echo "提交SHA: ${CI_COMMIT_SHA:0:7}"'
- echo ""
- echo "9.1 切换到main分支"
- 'git checkout main || { echo "❌ 切换到main分支失败"; exit 1; }'
- echo ""
- echo "9.2 拉取最新main分支"
- 'git pull origin main --no-rebase || { echo "❌ 拉取main分支失败"; exit 1; }'
- echo ""
- echo "9.3 合并当前分支到main"
- 'git merge "$CURRENT_BRANCH" --no-ff -m "archive: $CURRENT_BRANCH → main [CI]" || { echo "❌ 合并分支失败"; exit 1; }'
- echo ""
- echo "9.4 创建版本标签"
- 'export VERSION_TAG="v$(date +%Y.%m.%d)-${CI_COMMIT_SHA:0:7}"'
- 'git tag -a "$VERSION_TAG" -m "Release: $CURRENT_BRANCH → $VERSION_TAG [CI]" || { echo "❌ 创建标签失败"; exit 1; }'
- echo ""
- echo "9.5 推送到远程仓库"
- 'git push origin main || { echo "❌ 推送main分支失败"; exit 1; }'
- 'git push origin --tags || { echo "❌ 推送标签失败"; exit 1; }'
- echo ""
- 'echo "✅ 归档成功完成!版本: $VERSION_TAG"'
when:
event:
- push