RTX 3050 - Order Now
Home / Blog / Tutorials / Connect GitLab CI to Self-Hosted AI on GPU
Tutorials

Connect GitLab CI to Self-Hosted AI on GPU

Integrate AI code analysis into your GitLab CI/CD pipeline using a self-hosted LLM on GPU. This guide covers pipeline configuration, merge request hooks, and automating code review comments powered by your private inference endpoint.

What You’ll Connect

After this guide, your GitLab CI pipelines will include an AI code review stage powered by your own GPU server — no API costs, no rate limits. Every merge request triggers automated analysis from a model running on dedicated GPU hardware, and the AI feedback posts directly as an MR comment.

The integration adds a CI job that extracts the merge request diff, sends it to your vLLM or Ollama endpoint, and uses the GitLab API to post the review. This embeds AI coding assistant capabilities natively into your GitLab workflow.

CI Pipeline –> AI Review Job –> curl to GPU Server (merge_request .gitlab-ci.yml generates diff /v1/chat/completions event) triggers job sends to LLM on dedicated GPU | | MR Comment <-- GitLab API POST <-- Job parses <-- AI review returned with review /notes endpoint JSON response -->

Prerequisites

  • A GigaGPU server with a code-capable LLM on an OpenAI-compatible API (vLLM guide)
  • A GitLab project (self-managed or GitLab.com) with CI/CD enabled
  • CI/CD variables for GPU_API_KEY and GPU_API_URL (set under Settings > CI/CD > Variables)
  • A GitLab personal access token with api scope stored as GITLAB_TOKEN variable
  • HTTPS access to your GPU server (Nginx proxy guide)

Integration Steps

Store your GPU API key and GitLab token as protected CI/CD variables in the project settings. Mark them as masked to prevent accidental exposure in job logs.

Add an AI review stage to your .gitlab-ci.yml. The job runs only on merge request pipelines, generates a diff between the source and target branches, sends the diff to your GPU inference API, and posts the result as a note on the merge request using the GitLab Notes API.

Limit the diff size sent to the model by filtering for relevant file extensions and truncating to fit the context window. The GitLab CI job uses standard tools like curl and jq available in most CI runner images.

Code Example

Add this job to your .gitlab-ci.yml to run AI reviews on merge requests via your FastAPI inference server:

# .gitlab-ci.yml
stages:
  - test
  - ai-review

ai_code_review:
  stage: ai-review
  image: alpine:3.19
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  before_script:
    - apk add --no-cache curl jq git
  script:
    - git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    - git diff origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD -- '*.py' '*.js' '*.ts' | head -c 12000 > diff.txt
    - |
      RESPONSE=$(curl -s "$GPU_API_URL/v1/chat/completions" \
        -H "Authorization: Bearer $GPU_API_KEY" \
        -H "Content-Type: application/json" \
        -d "$(jq -n --rawfile diff diff.txt '{
          model: "deepseek-ai/DeepSeek-Coder-V2-Instruct",
          messages: [
            {role: "system", content: "Review this code diff for bugs, security issues, and improvements. Be concise."},
            {role: "user", content: $diff}
          ],
          max_tokens: 1000
        }')")
      REVIEW=$(echo "$RESPONSE" | jq -r '.choices[0].message.content')
    - |
      curl -s --request POST \
        "$CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes" \
        --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
        --header "Content-Type: application/json" \
        --data "$(jq -n --arg body "## AI Code Review\n\n$REVIEW" '{body: $body}')"

Testing Your Integration

Create a merge request with a small code change. The pipeline should include the ai_code_review job, which runs after your test stage. Once complete, check the MR’s comment thread for the AI review note. Verify the feedback references actual changes in the diff.

Test with merge requests of varying sizes. For very large MRs, confirm the diff truncation works correctly and the model still provides actionable feedback. Monitor GPU server logs to verify requests arrive from the CI runner.

Production Tips

If your GitLab instance is self-managed and on the same network as your GPU server, you can skip the public HTTPS layer and route requests over the private network. This reduces latency and eliminates the need for public endpoint exposure.

Add the AI review as an optional job (using allow_failure: true) so it never blocks merge request pipelines. Developers benefit from the review without being gated by AI availability. Consider adding a “skip-ai-review” label that excludes the job for trivial changes.

For engineering teams building with open-source code models on dedicated GPUs, CI-integrated reviews provide consistent analysis without per-token costs or vendor dependencies. Explore more tutorials or get started with GigaGPU to add AI to your GitLab pipelines.

Need a Dedicated GPU Server?

Deploy from RTX 3050 to RTX 5090. Full root access, NVMe storage, 1Gbps — UK datacenter.

Browse GPU Servers

admin

We benchmark, deploy, and optimise GPU infrastructure for AI workloads. All data in our guides comes from real-world testing on our UK-based dedicated GPU servers.

Ready to deploy your AI workload?

Dedicated GPU servers from our UK datacenter. NVMe storage, 1Gbps networking, full root access.

Browse GPU Servers Contact Sales

Have a question? Need help?