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

如何配置GitHub Actions Job的if条件仅在上游触发时运行?

解决方案

你可以给Job添加如下if条件来实现需求:

jobs:
  your-job-name:
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
    # 其他Job配置内容...

条件说明:

  • github.event_name != 'pull_request':匹配push事件,这类事件都是直接推送到上游main分支的操作,会直接运行Job
  • github.event.pull_request.head.repo.full_name == github.repository:当事件是pull_request时,只有PR的发起仓库(head.repo)和当前工作流所在的上游仓库(github.repository)完全一致时,才运行Job;如果是fork仓库发起的PR,这两个仓库名称会不一致,Job就会被跳过

内容的提问来源于stack exchange,提问作者LuMa

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 14:02:06