wrangler versions upload --preview-alias rejects raw WORKERS_CI_BRANCH values containing slashes in Workers Builds
What versions & operating system are you using?
System: OS: Windows 11 10.0.26200 CPU: (16) x64 AMD Ryzen 7 7700 8-Core Processor Memory: 16.09 GB / 31.11 GB Binaries: Node: 22.22.3 - C:\nvm4w\nodejs\node.EXE npm: 11.17.0 - C:\Users\mynameistito\node_modules.bin\npm.EXE pnpm: 11.3.0 - C:\Users\mynameistito.local\share\pnpm\bin\pnpm.CMD bun: 1.3.14 - C:\Users\mynameistito.bun\bin\bun.EXE Deno: 2.8.3 - C:\Users\mynameistito\node_modules.bin\deno.EXE npmPackages: @cloudflare/vite-plugin: ^1.41.0 => 1.41.0 wrangler: ^4.101.0 => 4.101.0
Please provide a link to a minimal reproduction
https://github.com/mynameistito/workers-preview-alias-repro
Describe the Bug
Workers Builds provides WORKERS_CI_BRANCH, but using it directly as a preview alias can fail for normal branch names that contain /. Repro: https://github.com/mynameistito/workers-preview-alias-repro/pull/1 Steps:
- Set up a Worker with Workers Builds.
- Enable non-production branch builds.
- Use a branch like: chore/simplify-wrangler-deploy
- Set the non-production deploy command to: bunx wrangler versions upload --preview-alias "${WORKERS_CI_BRANCH}"
- Run the build. The deploy fails because WORKERS_CI_BRANCH is passed through as: chore/simplify-wrangler-deploy Wrangler rejects that alias: validation failures: invalid alias: chore/simplify-wrangler-deploy [code: 10021] I expected this to either work out of the box, or for Workers Builds to provide a sanitized branch alias that can be passed to --preview-alias. Current workaround is to sanitize the branch manually before calling Wrangler: ALIAS="$(printf '%s' "$WORKERS_CI_BRANCH" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9_-]+/-/g; s/-+/-/g; s/^-+//; s/-+$//' | cut -c1-63)" && bunx wrangler versions upload --preview-alias "${ALIAS:-preview}" Tested with Wrangler 4.101.0.
Please provide any relevant error logs
No response
I'd like to fix this. The rejection is server-side (code: 10021) — --preview-alias is passed straight to the API without client-side validation, so users get a cryptic error instead of guidance (aliases must be lowercase alphanumeric + -/_, ≤63 chars).
Two directions, happy to PR whichever you prefer:
- Validate client-side with an actionable error — fail fast in wrangler with a message stating the allowed format and a suggested sanitized alias (e.g.
chore/simplify-wrangler-deploy→chore-simplify-wrangler-deploy). No behavior change; just turns10021into something legible. - Auto-sanitize the alias (optionally with a warning) — coerce to the valid charset so
--preview-alias "$WORKERS_CI_BRANCH"works out of the box, matching the reporter's expectation. This silently changes user input, so it's more of a product decision.
My lean is (1). Which would you accept? Happy to open a PR with tests + a changeset.
Thanks for the detailed report. Wrangler already sanitizes the branch name for you: set the build variable WRANGLER_CI_GENERATE_PREVIEW_ALIAS=true and run wrangler versions upload without --preview-alias. It derives the alias from WORKERS_CI_BRANCH, so chore/simplify-wrangler-deploy becomes chore-simplify-wrangler-deploy, lowercased and truncated to fit. --preview-alias is passed through as-is, which is why the raw value is rejected. If that doesn't work for you, reply here and we'll take another look.