#!/usr/bin/env python3 """ Woodpecker CI 自动触发诊断工具 排查 CI 无法自动触发的可能原因 """ import yaml from pathlib import Path def diagnose_auto_trigger(config_path): """诊断自动触发问题""" with open(config_path, 'r', encoding='utf-8') as f: config = yaml.safe_load(f) print("="*70) print("Woodpecker CI 自动触发诊断") print("="*70) print("\n🔍 可能导致 CI 无法自动触发的原因:") print("-"*70) reasons = [ { "原因": "1. Webhook 未配置或配置错误", "检查": "Git 仓库设置 → Webhooks → 确认有指向 Woodpecker CI 的 Webhook", "解决": "添加 Webhook,URL 格式: http://woodpecker-server/hook" }, { "原因": "2. Woodpecker CI 仓库未激活", "检查": "Woodpecker CI Web 界面 → 确认仓库已激活", "解决": "在 Woodpecker CI 中激活仓库" }, { "原因": "3. 分支保护或限制", "检查": "Woodpecker CI 仓库设置 → 查看 'Trusted' 和 'Protected' 设置", "解决": "取消分支保护或添加受信任的分支" }, { "原因": "4. 配置文件语法错误", "检查": "使用 yamllint 或在线 YAML 验证器检查配置文件", "解决": "修复 YAML 语法错误" }, { "原因": "5. when 条件过于严格", "检查": "检查配置文件中的 when 条件", "解决": "确保 when 条件包含正确的分支和事件" }, { "原因": "6. Woodpecker CI 全局配置限制", "检查": "检查 Woodpecker CI 的全局配置文件", "解决": "修改全局配置,允许自动触发" }, { "原因": "7. Git 仓库权限问题", "检查": "确认 Woodpecker CI 有访问仓库的权限", "解决": "重新授权 Woodpecker CI 访问仓库" }, { "原因": "8. 提交信息包含跳过关键词", "检查": "检查提交信息是否包含 [skip ci], [ci skip] 等", "解决": "避免在提交信息中使用跳过关键词" } ] for i, reason in enumerate(reasons, 1): print(f"\n{reason['原因']}") print(f" 检查: {reason['检查']}") print(f" 解决: {reason['解决']}") # 检查配置文件中的 when 条件 print("\n\n📋 当前配置的 when 条件:") print("-"*70) for step_name, step_config in config.get('steps', {}).items(): if not isinstance(step_config, dict): continue when = step_config.get('when', {}) if not when: continue if isinstance(when, dict): events = when.get('event', []) branches = when.get('branch', []) if events or branches: print(f"\n步骤: {step_name}") if events: print(f" 事件: {events}") if branches: print(f" 分支: {branches}") elif isinstance(when, list): print(f"\n步骤: {step_name}") for condition in when: if isinstance(condition, dict): events = condition.get('event', []) branches = condition.get('branch', []) if events: print(f" 事件: {events}") if branches: print(f" 分支: {branches}") print("\n\n💡 快速排查步骤:") print("="*70) print("1. 访问 Git 仓库设置 → Webhooks") print(" - 确认有 Woodpecker CI 的 Webhook") print(" - 查看 'Recent Deliveries' 是否有发送记录") print("\n2. 访问 Woodpecker CI Web 界面") print(" - 确认仓库已激活") print(" - 检查仓库设置中的 'Trusted' 选项") print("\n3. 查看提交记录") print(" - 确认提交信息不包含 [skip ci] 等关键词") print("\n4. 手动触发测试") print(" - 在 Woodpecker CI 中手动触发 Pipeline") print(" - 观察是否能够正常执行") print("\n" + "="*70) if __name__ == "__main__": diagnose_auto_trigger(".woodpecker.yml")