Schedule icon
Request icon
Return icon
Switch icon
Log icon
SlackIncomingWebhook icon

Bitbucket Pipelines Failure Sentinel

Read recent Bitbucket Pipelines runs every hour, run nothing, and alert Slack when failed builds cross your limits or a pipeline is stuck.

Categories
Infrastructure

Teams on Bitbucket Cloud find out that CI is broken one notification at a time: a failed build email here, a red merge check there. When a dependency release, an expired credential or a flaky runner starts failing pipelines across branches, nobody sees the rate until merges pile up. This blueprint turns a scheduled, read-only call to the Bitbucket Cloud Pipelines API into a CI health gate: io.kestra.plugin.core.http.Request reads the latest pipelines, one jq query computes the failure rate, the stuck pipelines and the branch that fails most, and the result routes to a quiet log or a Slack alert.

How it works

  1. list_pipelines (io.kestra.plugin.core.http.Request) calls GET /2.0/repositories/{workspace}/{repo_slug}/pipelines?sort=-created_on&pagelen=100 with HTTP basic auth (your Atlassian account email and an API token, or a username and app password). It is a read: no pipeline is run, stopped or re-run. Retries cover short network blips, and allowFailed plus allowFailure keep an API error from aborting the flow so it can be reported instead.
  2. summarize_pipelines (io.kestra.plugin.core.debug.Return) first guards for a missing or non-200 response (UNREACHABLE). Otherwise one jq query keeps pipelines whose created_on is in the lookback window, takes the ones whose state.name is COMPLETED, and computes the share whose state.result.name is FAILED or ERROR. STOPPED and EXPIRED are reported but not counted as failures. Pipelines still PENDING or IN_PROGRESS longer than stuck_minutes count as stuck. At or above critical_failure_rate is CRITICAL; at or above warning_failure_rate, or any stuck pipeline, is WARNING; fewer than min_pipelines completed is LOW_VOLUME; otherwise HEALTHY.
  3. route_by_failures (io.kestra.plugin.core.flow.Switch) branches on that classification: HEALTHY and LOW_VOLUME log quietly, WARNING posts a Slack note, CRITICAL and UNREACHABLE page Slack. A defaults fallback logs anything unexpected.
  4. log_audit_result (io.kestra.plugin.core.log.Log) writes one audit line per run with the HTTP status and the full summary.
  5. The flow-level errors block pages Slack if the flow itself fails, and the hourly_check trigger runs at 20 minutes past every hour, shipped disabled: true.

What you get

  • An hourly, read-only check of CI health for one repository with no custom scripting and no extra plugin to install.
  • A status output (HEALTHY / WARNING / CRITICAL / LOW_VOLUME / UNREACHABLE) other flows can gate on, for example to hold a release or a deploy while CI is red.
  • Slack messages with the failure rate, the number of stuck pipelines and the branch that fails most.
  • Build minutes used in the window in every log line, which helps keep an eye on the Pipelines minutes quota.

Who it's for

  • Engineering teams running CI on Bitbucket Pipelines.
  • Platform and DevOps teams responsible for runners, credentials and shared pipeline configuration.
  • Teams that already run their alerting in Kestra.

Why orchestrate this with Kestra

Bitbucket notifies the person who triggered a build, one build at a time. Kestra turns a plain, read-only API call into a scheduled, typed classification with retries, a failure path and an execution history, and the status output lets your release flows wait for green CI automatically.

Prerequisites

  • A Bitbucket Cloud repository with Pipelines enabled.
  • An Atlassian API token with read access to Bitbucket repositories and pipelines (or a Bitbucket app password with Pipelines: Read), and the matching username or account email.
  • A Slack incoming webhook for the WARNING, CRITICAL, UNREACHABLE and flow-failure alerts.

Secrets

  • BITBUCKET_USERNAME: the basic-auth username (your Atlassian account email for an API token, or your Bitbucket username for an app password).
  • BITBUCKET_API_TOKEN: the API token or app password (basic-auth password).
  • SLACK_WEBHOOK: Slack incoming webhook used for every alert branch and the flow-failure alert.

In Kestra OSS, secrets are supplied as environment variables prefixed SECRET_ and base64-encoded, for example SECRET_BITBUCKET_API_TOKEN=$(echo -n 'xxxxxxxx' | base64), and read back with {{ secret('BITBUCKET_API_TOKEN') }}. Use the Enterprise secrets backend for encryption at rest and access control.

Quick start

  1. Create the API token (or app password) with read access to pipelines.
  2. Add BITBUCKET_USERNAME, BITBUCKET_API_TOKEN and SLACK_WEBHOOK as secrets, and set workspace and repo_slug.
  3. Run the flow manually with a low min_pipelines and compare the counts in the logs with the repository's Pipelines page.
  4. Enable hourly_check.

How to extend

  • Add target.branch=main to the request to watch only the main branch with stricter limits.
  • Run one execution per repository with a ForEach over a list of repo_slug values.
  • Follow next when more than 100 pipelines run in the window (completed and running show the counts).
  • Store the last status in a KV store to alert only on changes.

Inputs

  • workspace: type STRING, default my-workspace.
  • repo_slug: type STRING, default my-repo.
  • lookback_hours: type INT, default 24.
  • warning_failure_rate: type FLOAT, default 15.0 (percent).
  • critical_failure_rate: type FLOAT, default 40.0 (percent).
  • min_pipelines: type INT, default 5.
  • stuck_minutes: type INT, default 90.

Outputs

  • status: one of HEALTHY, WARNING, CRITICAL, LOW_VOLUME, UNREACHABLE.
  • Example path: {{ fromJson(outputs.summarize_pipelines.value).top_branch }} for the branch with the most failures.

Links

Pitfalls

  • Only the first page (100 pipelines, newest first) is read; busy repositories need paging or a shorter window.
  • The window compares created_on with a UTC cutoff; Bitbucket returns timestamps in UTC.
  • STOPPED (cancelled) and EXPIRED pipelines are not counted as failures.
  • This flow only reads; it never runs, stops or re-runs a pipeline.
See How

New to Kestra?

Use blueprints to kickstart your first workflows.