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

GitHub Actions:作业超时后未触发后续作业问题排查

问题原因

cancelled() 函数仅在整个工作流被手动取消时返回 true,单个作业超时导致的终止并不会触发这个函数。你看到的页面注释里的“build The operation was canceled.”只是单个作业的状态,并非整个工作流被取消,所以cancel作业的条件永远无法满足。

解决方案

要在build作业超时(或被取消)时触发cancel作业,需要做两处修改:

  • 让cancel作业依赖build作业,确保build执行完成后才会启动cancel
  • 检查build作业的具体状态,而非判断整个工作流是否被取消

修改后的Workflow代码如下:

name: test

on:
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
jobs:
  build:
    timeout-minutes: 1
    runs-on: ubuntu-latest
    steps:
      - name: test
        run: |
          while true; do echo 1; sleep 1; done

  cancel:
    needs: build
    if: ${{ needs.build.result == 'cancelled' }}
    runs-on: ubuntu-latest
    steps:
      - name: cancel
        run: |
          echo "cancel"

如果需要同时覆盖作业失败、超时等多种异常终止场景,可以把条件调整为:

if: ${{ needs.build.result == 'cancelled' || needs.build.result == 'failed' }}

内容的提问来源于stack exchange,提问作者afraid.jpg

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 09:47:00