Skip to content
Latchkey

How to Deploy a Static Site to Netlify From CI

The Netlify CLI pushes a build directory straight to a site when given an auth token and site id.

Install netlify-cli, then run netlify deploy --prod --dir=<build> with NETLIFY_AUTH_TOKEN and NETLIFY_SITE_ID in the environment. Omit --prod for a draft deploy.

Steps

  • Create a personal access token in Netlify user settings.
  • Store NETLIFY_AUTH_TOKEN and NETLIFY_SITE_ID as CI secrets.
  • Build the site, then run netlify deploy --prod --dir=dist.
  • Read the deploy URL from the CLI output.

Workflow

.github/workflows/ci.yml
jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
      NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - run: npx netlify-cli deploy --prod --dir=dist

Gotchas

  • Without --prod the CLI creates a draft deploy at a random preview URL.
  • --dir must point at the build output, not the project root.
  • If linking is not set, pass --site=$NETLIFY_SITE_ID explicitly.

Related guides

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