Git Worker Builds: Branch Control, Cache, Watch Paths and Hooks
How Cloudflare Workers Builds connects Git to automated build and deploy, including triggers, caching, monorepos, Deploy Hooks, and troubleshooting.
This page summarises Cloudflare’s documentation on Workers Builds: the native CI/CD path that links a Worker to Artifacts, GitHub, GitLab, or Cursor Origin and runs build and deploy steps on each push. For self-hosted GitHub or GitLab, or other providers, Cloudflare points you to external CI/CD with Wrangler instead of Workers Builds (CI/CD overview).
Workers Builds: what runs when you push to Git
Section titled “Workers Builds: what runs when you push to Git”Workers Builds is triggered when you push to a connected repository. Cloudflare describes a two-step flow on each commit:
When a commit is pushed to your connected repository, Workers Builds runs a two-step process:
Build command (optional) - Compiles your project (for example, a package build script for frameworks like Next.js or Astro) Deploy command - Deploys your Worker to Cloudflare (defaults to npx wrangler deploy)
— Cloudflare, Build configuration
Preview builds use a Preview command (default npx wrangler preview) so branch work updates a Preview without promoting production. Production branch builds that deploy create a new version and can promote the Active Deployment; non-production branches get Preview URLs (Builds overview).
The Cloudflare Git integration connects Artifacts, GitHub, GitLab, or GitLab-style hosting on push:
The Cloudflare Git integration lets you connect a new or existing Worker to a repository hosted by Artifacts, GitHub, or GitLab, enabling automated builds and deployments for your Worker on push.
— Cloudflare, Builds
Git status in the provider (GitHub check runs, GitLab commit statuses, Cursor Origin check runs) lets you see build outcome without opening the dashboard (Git integration, GitHub integration).
Connect a new or existing Worker to a repository
Section titled “Connect a new or existing Worker to a repository”- In the Cloudflare dashboard, open Workers & Pages and create an application or select an existing Worker.
- Choose Artifacts, GitHub, or GitLab, authenticate if prompted, and pick the repository (Connect a new Worker).
- For an existing Worker, go to Settings → Builds → Connect and configure build settings (Connect an existing Worker).
- Push a commit to start the first build and deploy.
Build settings: commands, root directory and build-time variables
Section titled “Build settings: commands, root directory and build-time variables”Build settings live under Settings → Build. Saved settings apply to the next build; a retry uses whatever configuration exists when the retry starts (Configuration).
| Setting | Role |
|---|---|
| Build command | Optional compile step (e.g. the project’s configured build script in package.json) |
| Deploy command | Wrangler deploy step (default npx wrangler deploy) |
| Preview command | Default npx wrangler preview for non-production branches |
| Root directory | Where commands run; required for monorepos |
| Build variables & secrets | Available at build time only, not Worker runtime |
Workers Builds does not honour Custom Builds defined only in wrangler.toml / wrangler.jsonc; configure commands in the dashboard (Configuration).
Default CI environment variables (WORKERS_CI_*)
Section titled “Default CI environment variables (WORKERS_CI_*)”Workers Builds injects variables similar to Cloudflare Pages so scripts can branch on deployment context:
| Variable | Value | Typical use |
|---|---|---|
CI |
true |
Detect CI vs local |
WORKERS_CI |
1 |
Detect Workers Builds vs other CI |
WORKERS_CI_BUILD_UUID |
Current build UUID | Correlate logs or workflows |
WORKERS_CI_COMMIT_SHA |
Commit SHA | Error reporting (e.g. Sentry) |
WORKERS_CI_BRANCH |
Branch from push | Turn off debug on production |
You can override these default values and add your own custom environment variables by navigating to your Worker > Settings > Environment variables.
— Cloudflare, Access git commit sha and branch name as environment variables in Workers Builds
Per-trigger variables can also be managed via the Builds API.
Branch control: production branch, previews and skipping queued builds
Section titled “Branch control: production branch, previews and skipping queued builds”The production branch defaults to the repository’s default branch but can be changed under Settings → Build → Branch control (Build branches). Each push to that branch runs the build command, then the deploy command.
Non-production branch builds update Previews—branch-oriented deployments that are not the same as Worker versions or gradual deployments (Builds). Preview URLs can appear on GitHub pull requests and GitLab merge requests within seconds after a build completes (changelog).
To build versions without promoting to active deployment, set the deploy command to npx wrangler versions upload (Disconnecting builds). Containers: preview flows using npx wrangler versions upload do not publish images or roll out container instances; production should use npx wrangler deploy (Deploy with Workers Builds).
Workers Builds and Cloudflare Pages both skip redundant queue work when newer commits pile up:
Workers Builds now automatically skips a queued build when a newer build for the same build trigger is also queued.
— Cloudflare, Workers Builds now skips superseded queued builds
For Pages-only branch pause behaviour, see branch deployment controls and Git integration.
Build caching: faster repeat builds and limits
Section titled “Build caching: faster repeat builds and limits”Build caching keeps dependency and framework output between builds in a shared project cache (Workers build caching).
Improve Workers build times by caching dependencies and build output between builds with a project-wide shared cache.
— Cloudflare, Build caching
Package manager directories (e.g. .npm, .pnpm-store, .cache/yarn) and framework paths (e.g. Next.js .next/cache, Astro node_modules/.astro) are detected from package.json. pnpm: if the store is not the default location, Workers Builds does not cache it (Build caching).
| Limit | Value |
|---|---|
| Retention | Purged 7 days after last read; unread artifacts 7 days after creation |
| Storage | 10 GB per project; LRU eviction when full |
Enable or clear cache under Settings → Build → Build cache, or purge per trigger via POST /builds/triggers/{uuid}/purge_build_cache in the Builds API. Pages caching additionally requires Build System V2 (Pages build caching).
Build watch paths and monorepo setup
Section titled “Build watch paths and monorepo setup”In a monorepo, every file change would otherwise trigger every connected Worker or Pages project. Build watch paths limit which paths start a build (Workers build watch paths, Pages build watch paths).
When you connect a git repository to Workers, by default a change to any file in the repository will trigger a build. You can configure Workers to include or exclude specific paths to specify if Workers should skip a build for a given path. This can be especially helpful if you are using a monorepo project structure and want to limit the number of builds being kicked off.
— Cloudflare, Build watch paths
For Workers monorepos (Advanced setups):
- Create one Worker per app and connect the same repository to each.
- Set root directory to the folder containing that app’s
wrangler.jsonc(e.g./workers/product-service/). - Optionally set per-Worker build/deploy commands (e.g.
turbo deploy -F product-service). - Optionally configure build watch paths so only relevant diffs trigger that Worker.
When watch paths skip a build, GitHub check runs / GitLab commit statuses for that Worker may not appear (GitHub integration). Pages monorepos allow up to five projects per repository without a limit increase (Monorepos).
Deploy Hooks: POST URLs for CMS, cron and custom pipelines
Section titled “Deploy Hooks: POST URLs for CMS, cron and custom pipelines”Besides Git push, Deploy Hooks start a build for a fixed branch when they receive POST (Deploy Hooks).
Each hook is a unique URL that triggers a manual build for one branch when it receives an HTTP POST request.
— Cloudflare, Deploy Hooks
Example trigger:
curl -X POST "https://api.cloudflare.com/client/v4/workers/builds/deploy_hooks/<DEPLOY_HOOK_ID>"No Authorization header is required; the URL acts as the credential. Hooks are rate-limited to 10 builds per minute per Worker and 100 per minute per account (Deploy Hooks). Duplicate POSTs while a build is still queued or initializing return the existing build_uuid with already_exists: true instead of enqueueing again.
Create hooks under Settings → Builds → Deploy Hooks. For token-based triggers with per-request branch choice, use POST /builds/triggers/{trigger_uuid}/builds in the Builds API. Pages has a parallel Deploy Hooks model for static projects.
Builds API: triggers, manual builds and logs
Section titled “Builds API: triggers, manual builds and logs”The Builds API reference targets automation: trigger builds, patch triggers, read logs, manage env vars, purge cache.
API calls use the Worker tag (external_script_id), not the Worker name:
Every Builds API endpoint that references a Worker requires the tag, not the name.
— Cloudflare, Builds API reference
A trigger holds build_command, deploy_command, root_directory, branch and path patterns, build_caching_enabled, and build-time environment_variables. Each Worker has at most two triggers—production and preview (What is a trigger?).
Typical flow: GET /workers/scripts → GET /builds/workers/{worker_tag}/triggers → POST /builds/triggers/{trigger_uuid}/builds with branch and/or commit_hash. Build logs and list results are retained 90 days after completion; versions and deployments remain for rollback (90-day retention). Install the Cloudflare GitHub App once in the dashboard before API repo connections (Prerequisites).
Common build failures and autofix for Wrangler name mismatches
Section titled “Common build failures and autofix for Wrangler name mismatches”Open Deployments → View build history and inspect the failed build (Troubleshooting builds). Builds and logs are kept 90 days (Troubleshooting builds).
Name mismatch between dashboard Worker name and name in wrangler.toml / wrangler.jsonc in the configured root directory is a frequent failure (Troubleshooting builds). Cloudflare can open a pull request to fix detectable issues, starting with that mismatch:
Before running your build, Cloudflare checks your Worker’s Wrangler configuration file (wrangler.toml or wrangler.jsonc) for common errors. Once you submit a build, if Cloudflare finds an error it can fix, it will submit a pull request to the connected repository that fixes it.
— Cloudflare, Autofix Worker name configuration errors at build time
Stale build token: if the selected token was deleted or rolled, create a new API token and select it in build settings, then retry (Troubleshooting builds).
Git integration: reinstall the GitHub or GitLab app via Settings → Builds → Manage under Git Repository (Troubleshooting builds, GitHub integration). For GitHub-only transient failures, use the failed check run → Details → Rerun (Retry from GitHub).
How to check this on your site
Section titled “How to check this on your site”- Confirm the Worker is connected under Settings → Builds and that production branch, root directory, and deploy command match the repository layout (Configuration).
- Push a small commit to the production branch and verify build status in the Worker Deployments tab and in GitHub check runs or GitLab commit status (Builds, GitHub integration).
- Push a non-production branch (with preview builds enabled) and confirm a Preview URL appears on the pull request or merge request (Builds).
- After enabling build cache, compare build duration on a second build and confirm package or framework cache paths in the build log (Build caching).
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match your project or the linked Cloudflare docs, email yimasynthetic@gmail.com with the page URL and the exact sentence you want clarified or corrected.