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

如何禁用GitHub Actions Concurrency?能否按分支配置?

GitHub Actions Concurrency 问题解决方法

一、完全禁用Concurrency功能

如果不需要任何并发控制,直接移除工作流文件(.github/workflows/下的YAML文件)里的concurrency配置块即可。之前你可能添加过类似这样的代码:

concurrency:
  group: ${{ github.ref }}
  cancel-in-progress: true

删掉这段配置后,所有提交的构建任务都会正常执行,不会被后续提交触发的任务取消。

二、按分支自定义Concurrency规则

如果需要对特定分支保留并发控制,其他分支不受影响,可以通过条件判断灵活配置:

1. 仅指定分支启用并发取消

比如只对main分支启用“新提交取消旧构建”的规则,其他分支禁用:

concurrency:
  group: ${{ github.ref == 'refs/heads/main' && github.ref || '' }}
  cancel-in-progress: ${{ github.ref == 'refs/heads/main' }}

这里group为空时不会触发并发控制,所以非main分支的每个提交都会独立执行构建。

2. 多分支匹配规则

如果要对main和所有release/开头的分支启用并发取消,其他分支禁用:

concurrency:
  group: >-
    ${{ 
      contains(fromJSON('["refs/heads/main", "refs/heads/release/*"]'), github.ref) 
      && github.ref 
      || '' 
    }}
  cancel-in-progress: >-
    ${{ 
      contains(fromJSON('["refs/heads/main", "refs/heads/release/*"]'), github.ref) 
    }}

3. 指定分支保留所有构建

如果想让feature/开头的分支不取消正在进行的构建,其他分支正常启用并发取消:

concurrency:
  group: ${{ github.ref }}
  cancel-in-progress: ${{ !contains(github.ref, 'refs/heads/feature/') }}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 01:15:38