AI Code Review for GitLab CI: Cloud and Self-Hosted
GitLab is the platform of choice for many enterprises — especially those running self-hosted instances for data sovereignty. Merlin AI Code Review is purpose-built for GitLab CI and supports both GitLab.com and self-hosted GitLab with private runners, making it the ideal AI review solution for GitLab shops.
Why GitLab teams choose Merlin AI Code Review
Teams running self-hosted GitLab are already serious about data control. Merlin AI Code Review matches that philosophy: the review binary runs inside your GitLab runner, your code never leaves your network (except for the diff sent to the AI provider via your own API key), and there's no external SaaS dependency.
Basic GitLab CI setup
stages:- reviewmerlin-review:stage: reviewimage: ubuntu:22.04script:- apt-get update -qq && apt-get install -y curl- curl -L https://github.com/Arunachalamkalimuthu/merlin-ai-code-review/releases/latest/download/merlin-linux-amd64 -o merlin- chmod +x merlin && ./merlin reviewvariables:GITLAB_TOKEN: $CI_JOB_TOKENANTHROPIC_API_KEY: $ANTHROPIC_API_KEYrules:- if: $CI_PIPELINE_SOURCE == "merge_request_event"
Self-hosted GitLab with private runners
If your GitLab instance is air-gapped or uses private runners, you can pre-download the Merlin AI Code Review binary and store it in your artifact registry or runner cache:
merlin-review:stage: reviewimage: ubuntu:22.04cache:key: merlin-binarypaths:- merlinscript:- |if [ ! -f merlin ]; thencurl -L https://github.com/Arunachalamkalimuthu/merlin-ai-code-review/releases/latest/download/merlin-linux-amd64 -o merlinchmod +x merlinfi- ./merlin reviewvariables:GITLAB_TOKEN: $CI_JOB_TOKENANTHROPIC_API_KEY: $ANTHROPIC_API_KEYrules:- if: $CI_PIPELINE_SOURCE == "merge_request_event"
Adding a security scan step
merlin-review:stage: reviewscript:- ./merlin review- ./merlin run /securityvariables:GITLAB_TOKEN: $CI_JOB_TOKENANTHROPIC_API_KEY: $ANTHROPIC_API_KEYrules:- if: $CI_PIPELINE_SOURCE == "merge_request_event"
Using CI_JOB_TOKEN vs. a personal access token
For most pipelines, CI_JOB_TOKEN is sufficient — it has permission to comment on merge requests. For webhook bot mode (enabling @merlin commands in MR comments), you'll need a project or group access token with api scope:
variables:GITLAB_TOKEN: $MERLIN_PROJECT_TOKEN # project access token stored as CI variable
Setting up AI provider secrets in GitLab
Navigate to your project → Settings → CI/CD → Variables. Add:
ANTHROPIC_API_KEY— your Claude API key, masked and protected- (Optional)
MERLIN_PROJECT_TOKEN— for bot mode
Using Ollama for fully private inference
For GitLab instances in air-gapped environments, run Ollama on a machine accessible to your GitLab runners and configure Merlin AI Code Review to use it:
[ai]provider = "ollama"model = "qwen2.5-coder:32b"ollama_base_url = "http://ollama.internal:11434"
This achieves completely air-gapped AI code review — no internet access required for the inference step.