Skip to content

The moment it happens

Get an email when a Bitbucket build fails

As soon as a pipeline or build fails, you get the commit and the pull request it belongs to.

Runs
The moment it happens
Apps
Bitbucket
AI
Not needed
Access
read:repository, read:pullrequest

Send this to your assistant

Create a ClickRuntime automation: whenever a build on our acme/web-app Bitbucket repo fails, email me the commit message, the author and a link to the pull request it belongs to.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

A Bitbucket pipeline fails at 6 pm after a developer has pushed and left for the day. The red cross appears on the commit, but nobody is looking at it. The next morning the main branch is still broken, three more people have pushed on top of it and the cause is now buried under several commits, which turns a five-minute fix into an hour of detective work.

When Bitbucket reports a pipeline state change, ClickRuntime receives the event at once and keeps only those with the state FAILED. It then looks up any pull requests tied to the failing commit and sends a notification that names the repository, the branch and the pull request, so the right person knows their change is the one that broke.

Teams that rely on pipelines for tests and deployment, and want broken builds treated as an immediate problem, are the natural users.

What you get out of it

  • Broken builds are fixed while they are fresh

    The author is told while the change is still in their head. A fix pushed within minutes is far cheaper than debugging after several unrelated commits have piled up on top.

  • The right person is pointed to the cause

    Looking up the pull request attached to the commit means the message identifies whose change failed. Nobody has to scroll the pipeline list to figure out who should look. That saves a round of questions in chat when several people pushed close together.

  • Main stays releasable

    A failure on the main branch blocks deployments. Hearing about it right away keeps the release path clear and avoids a hotfix that is held up by a red build nobody noticed.

  • Failed deployments get caught after hours

    Pipelines that deploy on merge can fail in the evening. An alert makes sure a failed production deploy is known to someone before customers feel it. Waking up to a customer report is a worse way to learn about it.

  • Fewer repeated broken pushes

    When the team sees a red build announced, others hold off merging on top of it. That discipline stops the cascade of commits that make a simple failure hard to diagnose.

How it works

What happens, step by step

  1. When a build status changes in Bitbucket, Bitbucket tells ClickRuntime straight away.

  2. ClickRuntime ignores everything except failed builds.

  3. It looks up the commit and the pull request it belongs to.

  4. You get an email with the build name, repository, commit message and a link to the pull request.

Before it runs live

  • Connect Bitbucket
  • Paste your automation's link into the other app's webhook settings

What you get

RunsThe moment it happens
Get an email when a Bitbucket build failsjust nowSucceeded
Email · Build failedBuild failed: tests on acme/web-app Fix currency rounding in checkout PR: https://bitbucket.org/acme/web-app/pull-requests/88

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Act only on the items that match your own rules, and skip the rest
  • Add an AI step, for example to summarize, sort or draft a reply
  • Add another app, for example also send it to Slack
  • Combine it with other Bitbucket steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
get_alerted_when_a_pipeline_or_build_fails.pyexample
from clickruntime import on_event, credentials, http, notify

BB = "https://api.bitbucket.org/2.0"

def bb(path, **params):
    resp = http.get(f"{BB}{path}", headers={"Authorization": f"Bearer {credentials.secret('BITBUCKET_TOKEN')}"}, params=params)
    resp.raise_for_status()
    return resp.json()

@on_event
def handle(event):
    status = event.json.get("commit_status", {})
    if status.get("state") != "FAILED":
        return {"skipped": status.get("state")}
    repo = event.json["repository"]["full_name"]
    commit = status["commit"]
    prs = bb(f"/repositories/{repo}/commit/{commit['hash']}/pullrequests").get("values", [])
    pr = prs[0]["links"]["html"]["href"] if prs else "no pull request"
    notify.email_me(f"Build failed: {status['name']} on {repo}",
                    f"{commit['message'].strip()}\nAuthor: {commit['author']['raw']}\nPR: {pr}\nBuild: {status['url']}")
    return {"commit": commit["hash"]}

FAQ

Common questions

Does it alert on every pipeline run or only failures?
Only failures. The event arrives for each state change, and the workflow keeps just those where the state is FAILED. Successful, in-progress and stopped runs are ignored, so the channel stays quiet unless something actually broke.
What if the failing commit has no pull request?
The lookup then finds nothing, and the notification still goes out with the repository, branch and commit. Direct pushes to a branch without a pull request are still reported; you simply lack the pull request link in the message.
Does it need a webhook set up in Bitbucket?
Yes, Bitbucket has to send pipeline events to the address ClickRuntime provides. You need admin permission on the repository or workspace to add it. Once configured, events reach the workflow as they happen with no polling delay.
What permissions does it need?
read:repository, read:pullrequest. Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run for each event the app sends.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Get an email when a Bitbucket build fails” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.