wrangler deploy: Publish Cloudflare Workers in CI
wrangler deploy builds and uploads your Worker to Cloudflare, replacing the older wrangler publish.
wrangler deploy is the core publish command for Workers. In CI it reads credentials from environment variables and the target config from wrangler.toml.
What it does
wrangler deploy bundles the Worker entry point, applies the bindings declared in wrangler.toml (KV, D1, R2, secrets), and uploads it to the account and route configured. --env selects a named environment block from wrangler.toml for staging vs production.
Common usage
# token + account id come from env vars in CI
export CLOUDFLARE_API_TOKEN=xxx CLOUDFLARE_ACCOUNT_ID=yyy
wrangler deploy
# deploy a named environment from wrangler.toml
wrangler deploy --env productionOptions
| Flag | What it does |
|---|---|
| --env <name> | Use a [env.<name>] block from wrangler.toml |
| --name <worker> | Override the Worker name |
| --var KEY:value | Inject a plaintext build var |
| --minify | Minify the bundle before upload |
| --dry-run | Build without uploading |
| CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID | CI credentials via env vars |
In CI
Set CLOUDFLARE_API_TOKEN (a scoped API token, not a global key) and CLOUDFLARE_ACCOUNT_ID as env vars; wrangler is non-interactive when both are present. Pin the wrangler version in your devDependencies so CI matches local behavior.
Common errors in CI
"Authentication error [code: 10000]" means the API token is missing, expired, or lacks the Workers Scripts edit permission. "More than one account available but unable to select one in non-interactive mode" means CLOUDFLARE_ACCOUNT_ID is unset. "A compatibility_date is required" means wrangler.toml is missing that field.