Skip to content

Cloudflare

Deploys a release artifact to Cloudflare, either as a Cloudflare Worker (optionally with static assets) or as a Cloudflare Pages site.

The target extracts a ZIP artifact and shells out to the wrangler CLI to perform the deployment. wrangler is bundled in the Craft Docker image.

Option Description
deployType worker (default) or pages.
projectName Cloudflare Pages project name. Required when deployType is pages.
productionBranch The Pages project’s production branch name. Optional — when omitted, Craft reads it from the Cloudflare API so the release lands on production. See Production deployments. Only used for deployType: pages.
wranglerCliPath Path to the wrangler binary. Default: wrangler (or the WRANGLER_BIN env var).
workingDir Subdirectory within the extracted artifact to deploy from. For worker deploys this is where the wrangler.toml lives.
Name Required Description
CLOUDFLARE_API_TOKEN Yes Cloudflare API token with permission to deploy (Account → Cloudflare Pages → Edit, or the equivalent Workers permissions). Passed to wrangler via the environment, never on the command line.
CLOUDFLARE_ACCOUNT_ID No Cloudflare account ID. This is an identifier, not a secret. When unset, wrangler auto-discovers it for single-account tokens; set it explicitly if your token can access multiple accounts.

wrangler pages deploy --branch <X> deploys to production only when <X> exactly matches the project’s server-side production branch; any other value silently produces a preview deployment (this is not an error). To make releases reliably land on production, Craft resolves the production branch as follows:

  1. If productionBranch is set in the config, it is used verbatim.
  2. Otherwise, if the account ID is known, Craft reads the project’s production branch from the Cloudflare API (GET /accounts/{id}/pages/projects/{name}) — the same call wrangler makes internally, so it needs no token scope beyond deploying.
  3. If neither is available, Craft omits --branch; a bare deploy from Craft’s temporary (non-git) directory defaults to production.

By default, this target:

  1. Looks for a single artifact matching cloudflare.zip (or *-cloudflare.zip). Override with includeNames.
  2. Extracts its contents (flattening a single top-level directory if present).
  3. Deploys via wrangler.

Cloudflare Worker (with a wrangler.toml in the artifact):

targets:
- name: cloudflare
deployType: worker
workingDir: worker

Cloudflare Pages (static site):

targets:
- name: cloudflare
deployType: pages
projectName: my-docs-site
# productionBranch is optional; inferred from the API when omitted.
  1. Create a cloudflare.zip artifact in your CI workflow (e.g. your Worker plus wrangler.toml, or the built static site for Pages).
  2. Configure the target in .craft.yml.
  3. Set CLOUDFLARE_API_TOKEN in your environment (and CLOUDFLARE_ACCOUNT_ID if your token can access multiple accounts).