如何配置Drone流水线:仅当Chrome浏览器测试失败时终止流水线
解决方案:Drone流水线中按浏览器控制测试失败行为
直接上可行的配置方案,核心是把不同浏览器的测试拆成独立的Drone步骤,分别控制失败后的行为:
具体配置示例(drone.yml)
kind: pipeline type: docker name: playwright-tests steps: - name: test-chrome image: mcr.microsoft.com/playwright:v1.40.0-jammy commands: - npm install - npx playwright test --browser chrome # 默认行为:步骤失败则终止整个流水线,无需额外配置 - name: test-firefox image: mcr.microsoft.com/playwright:v1.40.0-jammy commands: - npx playwright test --browser firefox failure: ignore # 测试失败时忽略错误,继续执行后续步骤 depends_on: [test-chrome] # 确保Chrome测试通过后才执行 - name: test-safari image: mcr.microsoft.com/playwright:v1.40.0-jammy commands: - npx playwright test --browser safari failure: ignore # 同样忽略失败,继续流水线 depends_on: [test-chrome]
关键说明
- 拆分步骤:必须把三个浏览器的测试拆成独立步骤,这样才能单独控制每个步骤的失败策略。如果在一个步骤里跑所有浏览器,没法区分处理。
- Chrome步骤:Drone默认会在步骤失败时立即终止整个流水线,所以Chrome测试失败后,Firefox和Safari的步骤根本不会启动,完全符合需求。
- Firefox/Safari步骤:
failure: ignore是核心配置,它告诉Drone即使这个步骤失败,也继续执行后续流程。同时,Drone会完整保留该步骤的错误日志,你可以在流水线报告里看到所有测试失败的详细信息,不会被隐藏。 - 依赖设置:
depends_on确保只有Chrome测试通过后,才会执行另外两个浏览器的测试,避免做无用功。
额外提示
如果你的项目需要先做依赖安装之类的前置操作,可以把这些抽到一个独立的初始化步骤,让三个测试步骤都依赖这个初始化步骤,避免重复安装:
- name: setup image: mcr.microsoft.com/playwright:v1.40.0-jammy commands: - npm install - name: test-chrome image: mcr.microsoft.com/playwright:v1.40.0-jammy commands: - npx playwright test --browser chrome depends_on: [setup] # 其余步骤同理,depends_on改为[setup, test-chrome]
内容的提问来源于stack exchange,提问作者Emad Armoun
相关产品推荐
相关产品推荐

