Skip to content

Build branches

Last updated View as MarkdownAgent setup

When you connect a git repository to Workers, commits made on the production branch produce a production build. To create Previews and, for GitHub and GitLab repositories, pull request comments for branches that are not your production branch, enable preview builds.

Change production branch

To change the production branch of your project:

  1. In Overview, select your Workers project.
  2. Go to Settings > Build > Branch control. Workers will default to the default branch of your git repository, but this can be changed in the dropdown.

Every push event made to this branch will trigger a build and execute the build command, followed by the deploy command.

Configure preview builds

Preview builds are builds for branches that are not your production branch.

New Workers use Worker Previews for preview builds by default. Their Preview command is npx wrangler preview.

To enable or disable preview builds:

  1. In Overview, select your Workers project.
  2. Go to Settings > Build > Branch control. The checkbox Enable Preview Builds allows you to enable or disable Preview Builds.

When enabled, every push to a branch that is not your production branch triggers a preview build. Workers Builds runs the build command, followed by the Preview command.

Existing Workers connected to Builds

Workers that were connected to Builds before Worker Previews keep the previous preview model until you complete a one-time switch.

  1. In the Cloudflare dashboard, go to Workers & Pages > your Worker > Settings > Builds. In the Set up Worker Previews banner, select Set up.

    Go to Workers & Pages ↗ Dialog showing Preview settings confirmation and the new Worker Previews command
  2. Configure the variables, secrets, and bindings your Worker needs for Previews. Previews do not use production settings. For instructions, refer to Get started.

  3. Review the new Preview command. Workers Builds replaces the current command with npx wrangler preview. Custom commands must invoke npx wrangler preview.

  4. Select Switch to Worker Previews.

After switching, pushes to branches that are not your production branch use Worker Previews.

Was this helpful?