You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Github Actions仅在QAS分支触发deployment_status等指定事件?

GitHub Actions 正确配置代码
name: Cypress

on:
  deployment_status:
  pull_request:
    branches:
      - qas
  push:
    branches:
      - qas

jobs:
  e2e:
    if: |
      (github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.event.deployment.ref == 'qas') ||
      github.event_name == 'pull_request' ||
      github.event_name == 'push'
    runs-on: ubuntu-latest

    steps:
      - name: Print URL
        run: echo Testing URL ${{ github.event.deployment_status.target_url }}

      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Node.js
        uses: actions/setup-node@v2-beta
        with:
          node-version: 14

      - name: Install modules
        run: yarn

      - name: Run Cypress
        uses: cypress-io/github-action@v2
配置说明
  • 事件声明层级要正确:deployment_status、pull_request、push是三个同级触发事件,不能嵌套在deployment_status配置项下,否则不会生效
  • deployment_status事件本身不支持直接配置branches过滤规则,因此需要在job的if条件中补充判断部署对应的分支为qas,同时保留原有的部署状态为成功的校验
  • if条件采用短路求值逻辑,不会出现非部署事件下读取部署字段报错的问题,覆盖了三种合规触发场景:
    • 部署状态事件:同时满足部署状态为成功、部署关联分支为qas
    • PR事件:仅针对目标分支为qas的PR触发(已在事件层过滤)
    • 推送事件:仅针对推送到qas分支的操作触发(已在事件层过滤)

内容的提问来源于stack exchange,提问作者Marcos.C

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 08:36:03