Guide to deploy from self-hosted GitLab to Vercel using GitLab CI/CD pipeline.
Prerequisites
- Vercel account with a project token
- GitLab repository with your project
1. Get Vercel Tokens
# Install Vercel CLInpm i -g vercel
# Login and link projectvercel logincd your-projectvercel linkGet your tokens from .vercel/project.json:
- Project ID:
projectId - Org ID:
orgId
Get Vercel Token:
# Go to: https://vercel.com/account/tokens# Create new token2. Add GitLab CI/CD Variables
In GitLab:
Project → Settings → CI/CD → VariablesAdd these variables:
VERCEL_TOKEN(your token, masked)VERCEL_ORG_ID(your org ID)VERCEL_PROJECT_ID(your project ID)
3. Create .gitlab-ci.yml
Basic Configuration
image: node:24
stages: - deploy
deploy_preview: stage: deploy only: - merge_requests script: - npm install -g vercel - vercel pull --yes --environment=preview --token=$VERCEL_TOKEN - vercel build --token=$VERCEL_TOKEN - vercel deploy --prebuilt --token=$VERCEL_TOKEN
deploy_production: stage: deploy only: - main script: - npm install -g vercel - vercel pull --yes --environment=production --token=$VERCEL_TOKEN - vercel build --prod --token=$VERCEL_TOKEN - vercel deploy --prebuilt --prod --token=$VERCEL_TOKEN