如何一次“取消运行”所有计划的github动作?

时间:2020-03-19 08:33:24

标签: github github-actions

是否可以选择一次取消对一个存储库中所有计划的github操作的运行。总是要单击此处并取消运行是很多点击。谢谢

enter image description here

2 个答案:

答案 0 :(得分:1)

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

以下脚本将 用于:

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

要运行以下脚本,您将需要一个personnal access token和仓库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

答案 1 :(得分:0)

我创建了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