-
Notifications
You must be signed in to change notification settings - Fork 15
Description
To reduce credits used on duplicate builds and redundant workflows turn on CircleCI using
Project > Project Settings > Advanced > Auto-cancel Redundant Workflows.
This only turns off duplicate workflow builds for non- default branches.
GitHub and CircleCI how to cancel redundant workflows in default master branch?
To cancel redundant workflows in the default branch (often called "master" or "main") on CircleCI, you can use a workaround since the "Auto-cancel redundant builds" feature doesn't apply to the default branch by default. Here's a summary of the steps:
-
Use CircleCI API: You can create a script that interacts with the CircleCI API to identify and cancel redundant workflows. This involves:
- Fetching the current workflow and pipeline details.
- Identifying older pipelines on the same branch.
- Canceling workflows in those older pipelines.
-
Add the Script to Your Workflow: You can include this script in your repository and configure it to run at the start of your workflow. Alternatively, you can add it as a pre-step in an existing job.
-
Set Up an API Token: You'll need to generate a personal API token in CircleCI and add it as an environment variable (e.g.,
MyToken) in your project settings.
For detailed instructions and example scripts, you can refer to the [CircleCI discussion forum](https://discuss.circleci.com/t/workaround-auto-cancel-redundant-builds-on-the-default-branch/39468) or the [official documentation](https://circleci.com/docs/skip-build/).
Let me know if you'd like help with the script or further clarification!
https://discuss.circleci.com/t/workaround-auto-cancel-redundant-builds-on-the-default-branch/39468