---
name: gitlab-failed-pipelines-on-main
description: "Every morning: GitLab pipelines that failed on the default branch since yesterday, with the failing job, error line, author and whether it is still red. Use when the user asks for this, or when it runs on a schedule."
---

# GitLab failed pipelines on main

Every morning: GitLab pipelines that failed on the default branch since yesterday, with the failing job, error line, author and whether it is still red.

A red default branch blocks everyone who rebases onto it, yet GitLab only emails the person who pushed, and that email lands next to fifty others. By standup half the team has hit it on their own and nobody knows who is fixing it.

The agent checks every project you list, finds pipelines that failed on the default branch since yesterday, reads the failing job's log and names the commit and author. If a later pipeline passed, the failure is marked as fixed, so the card only turns red when main is red right now.

## Two ways to get the data

Use the API or MCP route when you have an MCP server, a CLI or an API token for the app. Otherwise, if you can drive a browser the user is signed in to (Claude in Chrome, a Playwright or Chrome DevTools MCP server), use the browser route. Say which one you used.

## Route A: API or MCP server

### What you need

- A GitLab token with `read_api` for the projects (Reporter role or higher) in `GITLAB_TOKEN`; `GITLAB_URL` for self-managed.
- Or the GitLab MCP server at `https://<your-gitlab>/api/v4/mcp`.

If something is missing, say what and stop; do not invent numbers.

### Steps

1. **Pick the projects and their default branch** (GitLab): Use the list in the prompt, or `GET /api/v4/groups/:id/projects?include_subgroups=true&archived=false`. Read each project's `default_branch`; not every repository uses `main`.
2. **List failed pipelines since yesterday** (GitLab): `GET /api/v4/projects/:id/pipelines?ref=<default_branch>&status=failed&updated_after=<24 hours ago, ISO 8601>&order_by=updated_at&sort=desc`. Keep `id`, `sha`, `source` and `web_url`.
3. **Find the failing job and its error** (GitLab): `GET /api/v4/projects/:id/pipelines/:pipeline_id/jobs?scope[]=failed` and skip jobs with `allow_failure: true`. Note `stage`, `name`, `failure_reason` and `commit.author_name`, then read the last 40 lines of `GET /api/v4/projects/:id/jobs/:job_id/trace` and keep the first line that reads as an error.
4. **Check whether it is still red** (GitLab): `GET /api/v4/projects/:id/pipelines/latest?ref=<default_branch>`. If it passed, mark the failure as fixed and say by which commit. If it failed on the same job, it is still broken.
5. **Report**: Still-red projects first, with job, error line, commit and author; fixed failures after, one line each. Flag a job that failed three or more times this week as likely flaky.

## Route B: the browser

### What you need

- Signed in to GitLab with an account that has at least the Reporter role on each project, so job logs open.

If something is missing, say what and stop; do not invent numbers.

### Steps

Start at https://gitlab.com/dashboard/projects. The user is signed in already; never type passwords or codes, and ask if a sign-in page appears.

1. **Open each project's pipeline list**: From the projects dashboard (replace the host for self-managed), open the first project to check, then in the left sidebar **Build > Pipelines**. The project's default branch is shown on the project home page next to the branch picker; it is not always `main`.
2. **Filter to failed pipelines on the default branch**: In the filter bar above the list choose **Status** `Failed` and **Branch name** `<default branch>`. Keep the rows whose created time is within the last 24 hours and note the pipeline ID, the commit title and the author avatar next to it.
3. **Open the failing job and read the error**: Click the pipeline, open the **Failed jobs** tab and skip jobs marked as allowed to fail. Open the job, scroll to the end of the log and copy the first line that reads as an error, plus the job name and stage.
4. **Check whether the branch is still red**: Go back to **Pipelines**, clear the Status filter and keep the branch filter. If the top row passed, the failure is fixed and its commit title says by what; if it failed on the same job, the branch is still red.
5. **Repeat and report**: Do the same for every project in the list. Still-red projects first with job, error line, commit and author; fixed failures after in one line each. A job that appears three or more times in this week's failed list is likely flaky.

Note: With more than a few projects this route gets slow, since each failure means three pages; the API route checks a group in one pass. Job logs longer than a few thousand lines are truncated in the browser view and need the **Show complete raw** link.

## The report

- **Still red**: project, pipeline, failing stage and job, error line, commit and author.
- **Fixed since**: failures a later pipeline already cleared, with the fixing commit.
- **Flaky**: jobs that failed three or more times this week.
- One line on who should look first.

## Post it to Briefkin

When `BRIEFKIN_TOKEN` is set, or `~/.config/briefkin/env` exists (the installer from https://briefkin.dev/docs writes it), also send the result to the user's Briefkin board as one card. Keep the `item_key` the same on every run so the card updates in place, use a new `event_id` per run, and put today's real numbers in place of the example ones. If the request fails, say so once and carry on.

```bash
[ -n "${BRIEFKIN_TOKEN:-}" ] || . ~/.config/briefkin/env
curl -sS -X POST "${BRIEFKIN_URL:-https://briefkin.dev}/v1/events" \
  -H "authorization: Bearer $BRIEFKIN_TOKEN" \
  -H "content-type: application/json" \
  -d @- <<'JSON'
{
  "v": 1,
  "event_id": "gitlab-failed-pipelines-on-main/<date of this run, e.g. 2026-10-16>",
  "item_key": "gitlab-failed-pipelines-on-main",
  "project": "acme",
  "source": "GitLab failed pipelines on main skill",
  "kind": "update",
  "title": "Main is red on the integration tests",
  "summary": "**3** pipelines failed on the default branch since yesterday. **1** is still red: acme/api, job `test:integration`, commit `9f3c2a1` by Lena.",
  "work_state": "failed",
  "widget": [
    {
      "type": "Table",
      "props": {
        "columns": [
          "Project",
          "Job",
          "Commit",
          "Now"
        ],
        "rows": [
          [
            "acme/api",
            "test:integration",
            "9f3c2a1 Lena",
            "Still failing"
          ],
          [
            "acme/web",
            "lint",
            "1d07e4b Tom",
            "Fixed by 5a9e310"
          ],
          [
            "acme/infra",
            "plan:staging",
            "c41b8d2 Sam",
            "Fixed by retry"
          ]
        ]
      }
    },
    {
      "type": "Log",
      "props": {
        "lines": [
          {
            "time": "06:12",
            "text": "Running tests/integration/webhooks.test.ts",
            "level": "info"
          },
          {
            "time": "06:14",
            "text": "Expected status 200, received 502 on POST /hooks/retry",
            "level": "error"
          },
          {
            "time": "06:14",
            "text": "ERROR: Job failed: exit code 1",
            "level": "error"
          }
        ]
      }
    },
    {
      "type": "Badges",
      "props": {
        "items": [
          {
            "label": "Still red 1",
            "tone": "bad"
          },
          {
            "label": "Fixed 2",
            "tone": "ok"
          },
          {
            "label": "test:integration failed 3x this week",
            "tone": "warn"
          }
        ]
      }
    }
  ]
}
JSON
```

Widgets come from the Briefkin catalog (https://briefkin.dev/v1/catalog). Without a token, just give the user the report.

## Run it on a schedule

Suggested: Every day at 8:30 (`30 8 * * *`). From cron, with the agent signed in on that machine:

```bash
30 8 * * * claude -p "Run the gitlab-failed-pipelines-on-main skill"
# Codex: codex exec, Gemini CLI: gemini -p, Copilot CLI: copilot -p, OpenCode: opencode run
```

Or use the agent's own scheduler (Claude Code routines, Codex automations, Claude or ChatGPT scheduled tasks): https://briefkin.dev/skills/gitlab-failed-pipelines-on-main#schedule

Source: https://briefkin.dev/skills/gitlab-failed-pipelines-on-main
