How to Deploy a Static Site to Cloudflare Pages From CI
wrangler pages deploy uploads a build directory to a named Cloudflare Pages project using an API token.
Run wrangler pages deploy <dir> --project-name=<name> with CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID set, or use cloudflare/wrangler-action to wrap it in a workflow step.
Steps
- Create a Cloudflare API token with the Pages Edit permission.
- Store the token and account id as CI secrets.
- Build the site, then run
wrangler pages deploy. - Pass
--project-namematching your Pages project.
Workflow
.github/workflows/ci.yml
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=my-siteGotchas
- The project must already exist in the Cloudflare dashboard or the deploy returns project not found.
- Add
--branch=mainto control which Pages environment (production vs preview) receives the upload. - A wildcard token scoped to the wrong account fails with authentication error 10000.
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 Purge the CDN Cache After Deploying a Static SitePurge the CDN cache after a static site deploy so the edge stops serving the old build, using CloudFront inva…