Skip to content

About

gitlab-incident-agent

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

GitLab Incident Response Agent

An autonomous SRE agent that watches for CI/CD pipeline failures in GitLab, investigates root causes using Gemini, and automatically creates issues and MR comments — so your on-call engineer wakes up to a pre-filled incident ticket instead of raw log noise.

Built for the Google Cloud Rapid Agent Hackathon — GitLab track.

Stack: Google Agent Development Kit (ADK) · Gemini 2.0 Flash · GitLab MCP Server · Cloud Run


What it does

When a GitLab pipeline fails, the agent automatically:

  1. Fetches pipeline details and job logs (via GitLab MCP)
  2. Lists recent commits on the failing branch
  3. Identifies the merge request that triggered the pipeline
  4. Searches for similar past incidents in the project
  5. Creates a structured GitLab issue with root cause, suspect commit, and fix suggestion
  6. Comments on the MR with a summary and link to the issue
  7. Returns a structured incident report

All without a human clicking anything.


Architecture

GitLab Pipeline Failure
        │
        ▼ (webhook)
  Cloud Run (server.py)
        │
        ▼
  Google ADK Runner
   └── Gemini 2.0 Flash
        │
        ▼ (MCP tools)
  GitLab MCP Server
   ├── get_pipeline / get_job_log
   ├── list_commits
   ├── get_merge_request
   ├── search_issues
   ├── create_issue
   └── create_mr_note

Setup (from scratch)

1. Google Cloud

  1. Go to console.cloud.google.com and create a free account
  2. Create a new project (e.g. gitlab-incident-agent)
  3. Enable billing (required for Cloud Run — free tier is generous)
  4. Enable these APIs:
    gcloud services enable run.googleapis.com \
      cloudbuild.googleapis.com \
      aiplatform.googleapis.com \
      secretmanager.googleapis.com
    
  5. Install the gcloud CLI and run:
    gcloud auth login
    gcloud config set project YOUR_PROJECT_ID

2. GitLab

  1. Go to gitlab.com and create a free account
  2. Create a test project (or use an existing one with CI pipelines)
  3. Generate a Personal Access Token:
    • User Settings → Access Tokens → Add new token
    • Scopes: api, read_repository
    • Copy the token — you won't see it again

3. Python environment

# Python 3.11+ required
python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt

# Node.js 18+ required (for the GitLab MCP server)
# Download from: https://nodejs.org

4. Configure environment

cp .env.example .env
# Edit .env and fill in GITLAB_TOKEN and GOOGLE_CLOUD_PROJECT

Run locally

Option A — Interactive chat (best for demos)

adk web

Opens a browser UI at http://localhost:8000. You can type incident scenarios like:

"Pipeline #123 failed on branch feature/auth in project mygroup/myrepo. Investigate and create an issue."

Option B — Webhook server

python server.py

Then use ngrok to expose it locally:

ngrok http 8080

Copy the ngrok HTTPS URL, then set it as a GitLab webhook:

  • Project → Settings → Webhooks
  • URL: https://YOUR-NGROK-URL/webhook/pipeline
  • Trigger: Pipeline events
  • Secret token: same value as GITLAB_WEBHOOK_SECRET in .env

Now trigger a pipeline failure and watch the agent work.


Deploy to Google Cloud Run

Build and deploy with one command

gcloud builds submit --config cloudbuild.yaml

This builds the Docker image, pushes it to Container Registry, and deploys to Cloud Run.

Store secrets securely

# Store your GitLab token in Secret Manager (don't bake it into the image)
echo -n "glpat-xxxx" | gcloud secrets create gitlab-token --data-file=-
echo -n "your-webhook-secret" | gcloud secrets create gitlab-webhook-secret --data-file=-

# Allow Cloud Run to read the secrets
gcloud secrets add-iam-policy-binding gitlab-token \
  --member="serviceAccount:$(gcloud iam service-accounts list --format='value(email)' | head -1)" \
  --role="roles/secretmanager.secretAccessor"

Get the Cloud Run URL

gcloud run services describe gitlab-incident-agent \
  --region=us-central1 \
  --format='value(status.url)'

Use this URL + /webhook/pipeline as your GitLab webhook endpoint.


Project structure

gitlab-incident-agent/
├── agent.py          # ADK agent definition + system prompt
├── server.py         # FastAPI webhook server
├── requirements.txt
├── Dockerfile
├── cloudbuild.yaml   # GCP CI/CD pipeline
├── .env.example
└── README.md

Judging criteria alignment

Criterion How this project addresses it
Move beyond chat Agent uses 6+ GitLab tools to actually investigate and create artifacts
Multi-step mission Investigate → Analyze → Act (issue + MR comment) — all automated
Partner power Deep GitLab MCP integration: logs, commits, MRs, issues, comments
Real-world challenge Solves a genuine SRE pain point (on-call alert fatigue)

License

Apache 2.0 — see LICENSE

About

gitlab-incident-agent

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages