Bitbucket Pipelines: stopping older pipelines on a new push
Push twice to a branch or a pull request, and Bitbucket runs both pipelines to the end, spending build minutes on the commit nobody needs any more. Bitbucket has no setting to cancel the older one. You can stop it by hand, or have the new pipeline stop it through the API, as Atlassian's support suggests.
No automatic cancel
Atlassian's support has said so in its community: "there is no automated way to do that" (February 2023), and Bitbucket Pipelines "does not natively support automatically canceling a running pipeline" for a pull request (December 2024). Two feature requests are open, both Gathering Interest:
- BCLOUD-23526 "Ability to cancel running pipeline for a PR when a new commit is pushed": 37 votes, opened December 2024.
- BCLOUD-22726 "Cancel previous builds when a new one starts - Self-hosted runners": 70 votes, opened June 2023.
A pipeline started with the atlassian/trigger-pipeline pipe is not stopped either when the pipeline that started it is (BCLOUD-23527).
Stop a pipeline
On Bitbucket, stop it from the running pipeline's page. With the REST API, Stop a pipeline:
curl -X POST -u '<email>:<API token>' \
https://api.bitbucket.org/2.0/repositories/WORKSPACE/REPO/pipelines/{PIPELINE_UUID}/stopPipeline
- 204: Bitbucket has been told to stop the pipeline and its unfinished steps. The pipeline then ends as STOPPED.
- 400: the pipeline has already completed. 404: no such workspace, repository or pipeline.
- The API token needs the
write:pipelinescope.
Let the new pipeline stop the old ones
The steps Atlassian's support suggested, for a step at the start of the pipeline:
- List the newest pipelines of the same branch (
$BB_AUTHbeingemail:API token):curl -u "$BB_AUTH" "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_FULL_NAME/pipelines/?target.branch=$BITBUCKET_BRANCH&sort=-created_on&pagelen=20"
- Keep those whose
state.nameisPENDINGorIN_PROGRESSand whosebuild_numberis lower than$BITBUCKET_BUILD_NUMBER, so the pipeline never stops itself or a newer one. - Send
stopPipelinefor eachuuid. A 400 only means that one finished in the meantime.
- Keep the credentials in a secured repository variable: an API token with
write:pipeline, or a repository access token that can write pipelines. - Leave deployments out (look at
target.selector): a deployment stopped halfway can leave the environment broken, as users point out in BCLOUD-22726. - On self-hosted runners, the new pipeline may wait in the queue behind the old one, and then this step runs too late. Atlassian notes that pipelines on its own infrastructure are not queued.
- One user's full Python script for pull requests is in a BCLOUD-23526 comment (February 2026).
Queue instead of cancel: concurrency groups
Since June 2025, a step can name a concurrency-group (Atlassian's announcement). Only one step of a group runs at a time, first in, first out, across pipelines; the others wait as Waiting to run. That keeps two runs of a deployment apart, but it does not stop the older one: every pipeline still runs.
Stop pipelines from IntelliJ IDEA
Pipeline Inbox for Bitbucket Pipelines, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the pipelines of all your Bitbucket Cloud repositories in an IDE tool window, with a running filter for those still waiting, running or paused at a manual step, and your current branch's pipeline in the status bar. Stop Pipeline on a running pipeline sends the same stopPipeline, so an outdated run on your branch can be stopped without opening Bitbucket. It does not stop pipelines by itself. The list, steps and logs are free; running, running again and stopping are Pro (US$1.50 a month, with a 30-day trial).
Get it on JetBrains Marketplace
Atlassian, Bitbucket and Bitbucket Pipelines are trademarks of Atlassian; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian or JetBrains.
More: Rerun a failed pipeline · Run a custom pipeline with variables · Out of build minutes · "No online runner available" · "Permission denied to update branch" · "You have reached your pull rate limit" (Docker Hub) · "There is an error in your bitbucket-pipelines.yml" · "This pipeline was paused" (deployments) · Bitbucket Pipelines plugins for IntelliJ IDEA compared · 日本語