Skip to content

wrangler versions upload --preview-alias rejects raw WORKERS_CI_BRANCH values containing slashes in Workers Builds #14345

Description

@mynameistito

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:
mynameistito/workers-preview-alias-repro#1
Steps:

  1. Set up a Worker with Workers Builds.
  2. Enable non-production branch builds.
  3. Use a branch like:
    chore/simplify-wrangler-deploy
  4. Set the non-production deploy command to:
    bunx wrangler versions upload --preview-alias "${WORKERS_CI_BRANCH}"
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:workers-buildsRelating to Workers Builds: https://developers.cloudflare.com/workers/ci-cd/#workers-builds

    Type

    No fields configured for Bug.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions