GitLab CI

Run Tabnine CLI on every GitLab merge request to automate code review, documentation, test generation, and more.

Overview

The Tabnine GitLab CI job runs the Tabnine CLI Agent as a pipeline stage on merge request events. The included configuration provides a comprehensive code review prompt that analyzes the MR diff and posts a summary note and inline discussion comments directly on the merge request. You can customize the prompt to automate any task — see Customizing the Prompt.

Prerequisites

  • A GitLab project with CI/CD pipelines enabled

  • A Tabnine account with Agents enabled

  • TABNINE_KEY - Tabnine Personal access token

  • GITLAB_API_TOKEN - A GitLab personal or project access token with api scope

Quick Setup

1

Add CI/CD variables

Go to your project's Settings > CI/CD > Variables and add:

Variable
Value
Options

TABNINE_KEY

Tabnine Personal Access Token

✅ Mask variable, ✅ Protect variable

GITLAB_API_TOKEN

GitLab access token with api scope

✅ Mask variable

2

Add the CI job

Copy the .gitlab-ci.yml from the tabnine-pr-agent repositoryarrow-up-right to the root of your GitLab repository.

If you already have a .gitlab-ci.yml, merge the review stage and tabnine-code-review job into your existing configuration:

.gitlab-ci.yml
stages:
  - review

tabnine-code-review:
  stage: review
  image: node:20
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
  variables:
    TABNINE_HOST: "https://console.tabnine.com"
    TABNINE_MODEL_ID: ""
  before_script:
    # Input validation
    - |
      if [ -z "$TABNINE_KEY" ]; then
        echo "Error: TABNINE_KEY not set"
        exit 1
      fi
      if [ -z "$GITLAB_API_TOKEN" ]; then
        echo "Error: GITLAB_API_TOKEN not set"
        exit 1
      fi

    - apt-get update -qq && apt-get install -y -qq curl git jq > /dev/null 2>&1

    # Install Tabnine CLI
    - |
      curl -fsSL "$TABNINE_HOST/update/cli/installer.mjs" -o installer.mjs
      node installer.mjs "$TABNINE_HOST"
      if [ ! -f ~/.local/bin/tabnine ]; then
        echo "Error: Tabnine CLI installation failed"
        exit 1
      fi

    # Configure git
    - git config user.name "Tabnine CLI Agent"
    - git config user.email "[email protected]"

    # Configure Tabnine Auth & Settings
    - |
      mkdir -p ~/.tabnine/agent
      MODEL_BLOCK=""
      if [ -n "$TABNINE_MODEL_ID" ]; then
        MODEL_BLOCK=",\"model\":{\"name\":\"$TABNINE_MODEL_ID\"}"
      fi
      cat << EOF > ~/.tabnine/agent/settings.json
      {
        "general": { "tabnineHost": "$TABNINE_HOST" },
        "security": { "auth": { "selectedType": "tabnine-personal" } }${MODEL_BLOCK}
      }
      EOF
      chmod 600 ~/.tabnine/agent/settings.json

  script:
    # The agent reviews the MR diff and posts comments
    - TABNINE_TOKEN=$TABNINE_KEY ~/.local/bin/tabnine -y -p "<REVIEW_PROMPT>"
  allow_failure: true

See the full configurationarrow-up-right for the complete review prompt.

3

Open a merge request

Push the configuration and open an MR. The Tabnine Code Review job will run automatically.

Configuration

Required CI/CD Variables

Variable
Description

TABNINE_KEY

Tabnine PAT. Mark as Masked and Protected.

GITLAB_API_TOKEN

GitLab personal or project access token with api scope. Mark as Masked.

Optional CI/CD Variables

Variable
Default
Description

TABNINE_HOST

https://console.tabnine.com

Tabnine host URL (for self-hosted / EMT installations)

TABNINE_MODEL_ID

Model ID for the AI agent. If empty, uses the system default from the admin console.

GitLab API Token

The GITLAB_API_TOKEN is used by the agent to interact with the GitLab API — fetching MR details, reading diffs, and posting comments.

Creating a token:

1

Go to User Settings > Access Tokens (personal) or Project Settings > Access Tokens (project-scoped)

2

Create a token with the api scope

3

Set an appropriate expiration date

4

Add it as a CI/CD variable named GITLAB_API_TOKEN

circle-info

Project access tokens are preferred over personal tokens for CI/CD use, as they are scoped to a single project and can be managed independently.

How It Works

1

Validates that TABNINE_KEY and GITLAB_API_TOKEN are set

2

Installs Tabnine CLI and dependencies (curl, git, jq)

3

Configures authentication and settings

4

Cleans up previous Tabnine PR Bot notes from the MR

5

Runs the review — the agent uses the GitLab API ($CI_API_V4_URL) to fetch MR changes, analyze the diff, and post notes and discussion comments

The job uses these GitLab CI predefined variables automatically:

  • CI_API_V4_URL — GitLab API base URL

  • CI_PROJECT_ID — Project ID

  • CI_MERGE_REQUEST_IID — MR internal ID

  • CI_MERGE_REQUEST_DIFF_HEAD_SHA — Head commit SHA

  • CI_MERGE_REQUEST_DIFF_BASE_SHA — Base commit SHA

Important Notes

circle-exclamation
circle-info

The job only runs on merge request events ($CI_PIPELINE_SOURCE == "merge_request_event"). It will not trigger on regular branch pushes.

Customization

Using a Specific Model

Set the TABNINE_MODEL_ID CI/CD variable in Settings > CI/CD > Variables, or override it in the job:

Self-Hosted / EMT Installations

Set the TABNINE_HOST variable:

Troubleshooting

chevron-right"Error: TABNINE_KEY not set"hashtag

The CI/CD variable is missing or empty.

Solution: Add TABNINE_KEY in Settings > CI/CD > Variables. Mark it as Masked and Protected.

chevron-right"Error: GITLAB_API_TOKEN not set"hashtag

The CI/CD variable is missing or empty.

Solution: Create a GitLab access token with api scope and add it as a CI/CD variable named GITLAB_API_TOKEN.

chevron-rightJob does not run on merge requestshashtag

The pipeline is not triggered by merge request events.

Possible causes:

  • The rules block is missing or misconfigured

  • The project does not have Merge request pipelines enabled

  • Check that the rule is: if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

chevron-rightNo comments appear on the MRhashtag

Possible causes:

  • The GITLAB_API_TOKEN lacks api scope

  • The MR diff is empty or contains only low-risk changes

  • Check the job logs for API errors

See Also

Last updated

Was this helpful?