【问题标题】:How to "cancel run" for all scheduled github actions at once?如何一次“取消运行”所有计划的 github 操作?
【发布时间】:2020-06-30 08:50:18
【问题描述】:

是否有一个选项可以一次取消一个存储库中所有计划的 github 操作的运行。总是去这里并取消运行是很多点击。谢谢

【问题讨论】:

标签: github github-actions


【解决方案1】:

您可以使用Github Actions API 列出工作流运行和取消工作流运行。

以下脚本使用 来:

  • 获取状态为queuedin_progress 的工作流运行的ID
  • 取消这些工作流运行

要运行下面的脚本,您需要一个 personnal access token 和 repo scope

token=YOUR_TOKEN
repo=your_user/your_repo

ids=$(curl -s -H "Authorization: token $token" \
     https://api.github.com/repos/$repo/actions/runs | \
     jq '.workflow_runs[] | select([.status] | inside(["in_progress", "queued"])) | .id')
set -- $ids
for i; do curl \
     -H "Authorization: token $token" \
     -X POST "https://api.github.com/repos/$repo/actions/runs/$i/cancel"; done

【讨论】:

  • 收到此错误curl: (3) URL using bad/illegal format or missing URL
【解决方案2】:

您还有,在 2021 年 10 月,gh run cancel

这来自GitHub CLI gh 2.2.0feature request 3775(支持取消工作流运行),在PR 3833commit 06c06c8 中实现

gh run cancel [<run-id>] [flags]

gh run list 可以先列出您的工作流运行 ID。

【讨论】:

    【解决方案3】:

    我创建了这个small script 来手动取消给定分支或拉取请求的所有未完成作业:

    Example:
    
      # Set up
      export GITHUB_TOKEN=394ba3b48494ab8f930fbc93
      export GITHUB_REPOSITORY=apache/incubator-superset
    
      # Cancel previous jobs for a PR
      ./cancel_github_workflows.py 1042
    
      # Cancel previous jobs for a branch
      ./cancel_github_workflows.py my-branch
    
      # Cancel all jobs including the last ones, this is useful
      # when you have closed a PR or deleted a branch and want
      # to cancel all its jobs.
      ./cancel_github_workflows.py 1024 --include-last
    

    【讨论】:

      【解决方案4】:

      gh运行列表+powershell:

      gh run list --limit 5000 --json status,databaseId -q ".[] | select (.status == \`"queued\`" ) | .databaseId" | ForEach-Object -Process { gh run cancel $_ }
      

      获取前 5000 个工作流,按 "status" == "queued" 对其进行过滤并将其传递给 "gh run cancel"

      【讨论】:

        猜你喜欢
        • 2022-09-28
        • 2016-04-24
        • 1970-01-01
        • 2020-04-05
        • 2021-11-16
        • 1970-01-01
        • 2021-05-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多