githubgithub-actions

How to "cancel run" for all scheduled github actions at once?


Is there an option to cancel runs for all scheduled github actions in one repository at once. To always go here and cancel runs is a lot of clicking. enter image description here


Solution

  • You can use Github Actions API to list workflow runs and cancel workflows runs.

    The following script use and to :

    To run the script below you will need a personnal access token with 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