Skip to content

GitLab CI/CD Integration

Run Claude Code inside GitLab pipelines (beta, maintained by GitLab). Same idea as GitHub Actions: @claude mentions and pipeline triggers turn issues/comments into MRs.

  • Turn an issue into a working MR: @claude implement this feature based on the issue description
  • Iterate on review feedback: @claude suggest a concrete approach to cache this API call
  • Fix bugs from comments: @claude fix the TypeError in the user dashboard component
  • Runs in your runners; every change flows through a normal MR with your branch protection and approvals
  1. Settings → CI/CD → Variables: add ANTHROPIC_API_KEY (masked)
  2. Add a job to .gitlab-ci.yml:
stages: [ai]
claude:
stage: ai
image: node:24-alpine3.21
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
variables:
GIT_STRATEGY: fetch
before_script:
- apk add --no-cache git curl bash
- curl -fsSL https://claude.ai/install.sh | bash
script:
- >
claude
-p "${AI_FLOW_INPUT:-'Review this MR and implement the requested changes'}"
--permission-mode acceptEdits
--allowedTools "Bash Read Edit Write mcp__gitlab"
  1. Optional @claude mention triggers: add a “Comments (notes)” webhook that calls the pipeline trigger API with AI_FLOW_INPUT / AI_FLOW_CONTEXT variables.

Instead of an API key, authenticate via OIDC (no stored keys):

  • Amazon Bedrock: GitLab OIDC → IAM role (AWS_ROLE_TO_ASSUME, AWS_REGION)
  • Google Cloud Agent Platform: Workload Identity Federation (GCP_WORKLOAD_IDENTITY_PROVIDER, GCP_SERVICE_ACCOUNT, CLOUD_ML_REGION)
  1. CLAUDE.md at repo root — Claude follows it in CI too
  2. Never commit keys; masked variables + OIDC where possible
  3. Set max_turns / job timeouts to bound cost; review Claude’s MRs like any contributor
  4. Specific @claude commands = fewer iterations = lower token cost

Compare: 35-github-actions.md — same concept, GitHub-native tooling and official Anthropic support.

  • Trick: “GitHub Actions’ sibling: one job + one masked variable.”
  • Do: walk the minimal .gitlab-ci.yml line by line.
  • They’ll trip on: keys in the repo — masked CI/CD variables or OIDC, always.

Learning path:46-jetbrains-and-terminal-setup.md · Index · ➡ 48-computer-use.md

Written by Fenil Patel