GitLab CI
Tabnine use is limited to one user per seat under the license agreement. If you want to use Tabnine in a CI/CD pipeline, please contact our team.
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 tokenGITLAB_API_TOKEN- A GitLab personal or project access token withapiscope
Quick Setup
Add CI/CD variables
Go to your project's Settings > CI/CD > Variables and add:
TABNINE_KEY
Tabnine Personal Access Token
✅ Mask variable, ✅ Protect variable
GITLAB_API_TOKEN
GitLab access token with api scope
✅ Mask variable
Add the CI job
Copy the .gitlab-ci.yml from the tabnine-pr-agent repository 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:
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 "TabnineCLI@tabnine.com"
# 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: trueSee the full configuration for the complete review prompt.
Open a merge request
Push the configuration and open an MR. The Tabnine Code Review job will run automatically.
Configuration
Required CI/CD Variables
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
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:
Go to User Settings > Access Tokens (personal) or Project Settings > Access Tokens (project-scoped)
Create a token with the api scope
Set an appropriate expiration date
Add it as a CI/CD variable named GITLAB_API_TOKEN
How It Works
Validates that TABNINE_KEY and GITLAB_API_TOKEN are set
Installs Tabnine CLI and dependencies (curl, git, jq)
Configures authentication and settings
Cleans up previous Tabnine PR Bot notes from the MR
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 URLCI_PROJECT_ID— Project IDCI_MERGE_REQUEST_IID— MR internal IDCI_MERGE_REQUEST_DIFF_HEAD_SHA— Head commit SHACI_MERGE_REQUEST_DIFF_BASE_SHA— Base commit SHA
Important Notes
allow_failure: true is recommended so that a review failure does not block your CI pipeline. Code review is advisory — it should not prevent merges.
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
See Also
Git Integrations Overview — Supported platforms and review capabilities
GitHub Actions — Setup for GitHub
Bitbucket Pipelines — Setup for Bitbucket
Last updated
Was this helpful?
