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_TOKENandNETLIFY_SITE_IDas 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=distGotchas
- Without
--prodthe CLI creates a draft deploy at a random preview URL. --dirmust point at the build output, not the project root.- If linking is not set, pass
--site=$NETLIFY_SITE_IDexplicitly.
Related guides
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…
How to Deploy a Static Site to Vercel From CIDeploy a static site or SPA to Vercel from CI with vercel --prod, using a VERCEL_TOKEN plus the org and proje…