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

GitHub Actions作业被跳过:push事件下最后两个作业为何未执行?

问题原因分析

在push事件中,你的job-four和job-five被跳过,根源在于job-three没有正常运行,具体原因如下:

  1. push事件触发时,job-one和job-two因if条件限制(仅PR事件才运行)被标记为跳过(skipped)。
  2. job-three依赖job-two,你当前的if条件是success() || github.event_name == 'push':
    • success()函数仅在所有依赖作业成功完成时返回true,而job-two是跳过状态,所以success()返回false。
    • 虽然github.event_name == 'push'为true,但GitHub Actions中,当依赖作业被跳过时,默认会跳过当前作业,除非你在if条件中明确允许这种情况。

因此job-three被跳过,后续依赖它的job-four和job-five自然也被跳过。

修复方案

根据你给出的作业运行规则,调整各作业的if条件如下:

name: Testing

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  job-one:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
    steps:
      - run: exit 0

  job-two:
    runs-on: ubuntu-latest
    needs: job-one
    if: github.event_name == 'pull_request' && (success() || failure())
    steps:
      - run: exit 0

  job-three:
    runs-on: ubuntu-latest
    needs: job-two
    # 符合规则:仅在Job2成功或被跳过的情况下运行
    if: success() || skipped(job-two)
    steps:
      - run: exit 0

  job-four:
    runs-on: ubuntu-latest
    needs: job-three
    # 符合规则:仅在push事件中运行,且Job3执行成功
    if: github.event_name == 'push' && success()
    steps:
      - run: exit 0

  job-five:
    runs-on: ubuntu-latest
    needs: job-four
    # 自动继承push事件上下文,且依赖job-four成功,符合规则
    steps:
      - run: exit 0

关键调整说明:

  • job-three的if条件改为success() || skipped(job-two):既覆盖PR事件中job-two成功的场景,也覆盖push事件中job-two被跳过的场景,确保job-three能正常运行。
  • job-four的if条件增加success():确保只有job-three成功时,job-four才会在push事件中运行,符合你的规则要求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 14:29:55