Skip to content
Latchkey

How to Deploy a Static Site to Vercel From CI

The Vercel CLI builds and deploys a project non-interactively when given a token and the org/project ids.

Run vercel --prod --token=$VERCEL_TOKEN with VERCEL_ORG_ID and VERCEL_PROJECT_ID set. The CLI reads these from the environment so no interactive linking is needed.

Steps

  • Create a token at Vercel account settings.
  • Get the org and project ids by running vercel link locally once.
  • Store VERCEL_TOKEN, VERCEL_ORG_ID, VERCEL_PROJECT_ID as secrets.
  • Run vercel --prod in the deploy job.

Workflow

.github/workflows/ci.yml
jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
      VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
    steps:
      - uses: actions/checkout@v4
      - run: npm i -g vercel
      - run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
      - run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
      - run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

Gotchas

  • The vercel pull step is what makes the org/project ids take effect.
  • Drop --prod on PR branches to produce a preview deployment.
  • vercel build then deploy --prebuilt avoids building twice on Vercel.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →