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 linklocally once. - Store
VERCEL_TOKEN,VERCEL_ORG_ID,VERCEL_PROJECT_IDas secrets. - Run
vercel --prodin 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 pullstep is what makes the org/project ids take effect. - Drop
--prodon PR branches to produce a preview deployment. vercel buildthendeploy --prebuiltavoids building twice on Vercel.
Related guides
How to Deploy a Static Site to Netlify From CIDeploy a static site to Netlify from CI with netlify deploy --prod, authenticating via NETLIFY_AUTH_TOKEN and…
How to Create a Preview Deploy Per Pull RequestPublish a preview deploy for every pull request from CI and post its URL back on the PR, so reviewers can cli…