# CircleCI workflow completed notifications on your phone

> Get a High-priority push notification when a CircleCI workflow fails or errors, and optionally a quiet one when it passes.

- Company: CircleCI (https://www.justpush.io/recipes/circleci)
- Event: `workflow-completed` (Workflow Completed)
- Tags: CI/CD, Builds & CI
- Install: https://studio.justpush.io/recipes/circleci/workflow-completed
- Web page: https://www.justpush.io/recipes/circleci/workflow-completed

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. In CircleCI, open your project's Project Settings > Webhooks and click Add Webhook (organization admins only).
3. Give it a name, paste your webhook URL (shown in Studio after install) as the URL and keep Certificate Validation on.
4. Tick the Workflow Completed event and save.
5. Click Test Ping Event to confirm it arrives.
6. In your project's **Project Settings → Webhooks**, add a webhook with the URL above and tick **Workflow Completed** (not Job Completed, or you'll get pushes for every job as well). A project can have up to five webhooks, and only organization admins can add them.
7. Only failed, errored and unauthorized workflows push by default. Add `?all=1` to the URL to also get a quiet push when a workflow succeeds or is canceled:
8. ```
9. your webhook URL (shown in Studio after install)?all=1
10. ```
11. **Test Ping Event** sends a quiet **🔔 CircleCI connected** push.
12. CircleCI signs each delivery with your secret token (`circleci-signature: v1=…`, HMAC-SHA256), but JustPush doesn't check that signature yet, so keep your endpoint URL private. You can leave the secret token empty.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// CircleCI → workflow-completed
// Fires when a CircleCI workflow reaches a final state. Failures push by default; add ?all=1
// to the webhook URL to also hear about successful and canceled workflows.
// Docs: https://circleci.com/docs/reference/outbound-webhooks-reference/

// Workflow statuses, how to describe them, and whether they push without ?all=1.
const STATUSES = {
    failed: { emoji: "❌", verb: "failed", priority: 1, always: true }, // broken build: needs you soon
    error: { emoji: "❌", verb: "errored", priority: 1, always: true }, // config or infrastructure error
    unauthorized: { emoji: "🔒", verb: "was not authorized", priority: 1, always: true }, // e.g. a restricted context
    success: { emoji: "✅", verb: "passed", priority: -1, always: false }, // good news, only with ?all=1
    canceled: { emoji: "⏹️", verb: "was canceled", priority: -1, always: false }, // on purpose, only with ?all=1
}

// Look a key up in a table without tripping over inherited names like "toString".
function pick(table, key, fallback) {
    return typeof key === "string" && Object.prototype.hasOwnProperty.call(table, key) ? table[key] : fallback
}

// Header names can arrive in any case.
function header(request, name) {
    const headers = request.headers || {}
    const key = Object.keys(headers).find((k) => k.toLowerCase() === name)
    const value = key ? headers[key] : null
    return Array.isArray(value) ? value[0] : value
}

// Treat blank or non-string values as missing.
function text(value) {
    return typeof value === "string" && value.trim() ? value.trim() : null
}

// Only link to real http(s) URLs.
function link(url, cta) {
    return typeof url === "string" && /^https?:\/\//.test(url) ? [{ cta, url }] : []
}

function handleRequest(request) {
    const body = request.body && typeof request.body === "object" ? request.body : {}
    const event = header(request, "circleci-event-type") ?? (typeof body.type === "string" ? body.type : null)

    // "Test Ping Event" in the webhook settings; confirm the connection quietly.
    if (event === "ping") {
        return {
            title: "🔔 CircleCI connected",
            message: `Webhook ${text(body.webhook?.name) ? `"${text(body.webhook.name)}" ` : ""}is working`,
            topic: "CircleCI",
            priority: -1,
        }
    }

    // Guard: only workflow-completed (the header, or the payload's own type field).
    if (event !== "workflow-completed" || !body.workflow || typeof body.workflow !== "object") {
        console.log(`Ignoring CircleCI "${event ?? "unknown"}" event`)
        return null
    }

    // ?all=1 on the webhook URL also sends quiet pushes for successful and canceled workflows.
    const all = ["1", "true", "yes"].includes(String(request.query?.all ?? "").toLowerCase())
    const status = pick(STATUSES, body.workflow.status, null)
    if (!status || (!status.always && !all)) {
        console.log(`Skipping workflow status "${body.workflow.status ?? "unknown"}"`)
        return null
    }

    // Git details live in pipeline.vcs (GitHub OAuth, Bitbucket) or pipeline.trigger_parameters
    // (GitLab, GitHub App). Every one of them is optional.
    const pipeline = body.pipeline ?? {}
    const vcs = pipeline.vcs ?? {}
    const params = pipeline.trigger_parameters ?? {}
    const provider = params.gitlab ?? params.github_app ?? {}
    const branch = text(vcs.branch) ?? text(params.git?.branch) ?? text(provider.branch)
    const tag = text(vcs.tag) ?? text(params.git?.tag)
    const subject = (text(vcs.commit?.subject) ?? text(provider.commit_title) ?? "").split("\n")[0]
    const author = text(vcs.commit?.author?.name) ?? text(provider.commit_author_name)

    const where = [text(body.project?.name), branch ?? (tag ? `tag ${tag}` : null)].filter(Boolean).join(" · ")
    const what = subject ? ` — ${subject}` : ""
    const who = author ? ` (${author})` : ""

    return {
        title: `${status.emoji} ${text(body.workflow.name) ?? "Workflow"} ${status.verb}`,
        message: (where || "A CircleCI project") + what + who,
        topic: "CircleCI",
        priority: status.priority,
        buttons: link(body.workflow.url, "View workflow"),
    }
}
```

## CircleCI workflow-completed webhook payload (sample)

```json
{
  "id": "3888f21b-eaa7-38e3-8f3d-75a63bba8895",
  "type": "workflow-completed",
  "project": {
    "id": "84996744-a854-4f5e-aea3-04e2851dc1d2",
    "name": "web",
    "slug": "github/acme/web"
  },
  "webhook": {
    "id": "cf8c4fdd-0587-4da1-b4ca-4846e9640af9",
    "name": "JustPush"
  },
  "pipeline": {
    "id": "1285fe1d-d3a6-44fc-8886-8979558254c4",
    "vcs": {
      "branch": "main",
      "commit": {
        "body": "Closes #88",
        "author": {
          "name": "Jane Doe",
          "email": "jane@example.com"
        },
        "subject": "Fix checkout totals rounding",
        "committer": {
          "name": "Jane Doe",
          "email": "jane@example.com"
        },
        "authored_at": "2026-09-24T22:48:53Z",
        "committed_at": "2026-09-24T22:48:53Z"
      },
      "revision": "1dc6aa69429bff4806ad6afe58d3d8f57e25973e",
      "provider_name": "github",
      "origin_repository_url": "https://github.com/acme/web",
      "target_repository_url": "https://github.com/acme/web"
    },
    "number": 130,
    "trigger": {
      "type": "webhook"
    },
    "created_at": "2026-09-24T22:49:03.544Z"
  },
  "workflow": {
    "id": "fda08377-fe7e-46b1-8992-3a7aaecac9c3",
    "url": "https://app.circleci.com/pipelines/github/acme/web/130/workflows/fda08377-fe7e-46b1-8992-3a7aaecac9c3",
    "name": "build-test-deploy",
    "status": "failed",
    "created_at": "2026-09-24T22:49:03.616Z",
    "stopped_at": "2026-09-24T22:49:34.170Z"
  },
  "happened_at": "2026-09-24T22:49:34.317Z",
  "organization": {
    "id": "f22b6566-597d-46d5-ba74-99ef5bb3d85c",
    "name": "acme"
  }
}
```

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into CircleCI and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
