When connecting your Git repository to your Worker, you can customize the configurations needed to build and deploy your Worker.
When a commit is pushed to your connected repository, Workers Builds runs a two-step process:
- Build command (optional) - Compiles your project (for example,
npm run buildfor frameworks like Next.js or Astro) - Deploy command - Deploys your Worker to Cloudflare (defaults to
npx wrangler deploy)
For preview builds, a Preview command runs instead (defaults to npx wrangler preview), which creates or updates a Preview without promoting it to production.
Workers Builds stores your Git connection and continuous integration (CI) settings. Your Worker project configuration describes the Worker you build and deploy. Neither Wrangler configuration nor cloudflare.config.ts stores Workers Builds settings.
The following table shows where each group of settings is stored and when it is applied:
| Configuration scope | Settings included | Source of truth | When applied |
|---|---|---|---|
| Workers Builds Git and CI configuration | Repository connection, production branch and preview triggers, build watch paths, build command, deploy command, Preview command, root directory, build caching, build API token, and build-time environment variables and secrets | Cloudflare Workers Builds. Use the Cloudflare dashboard (Settings > Build), the Cloudflare CLI (cf), or the Builds API. |
When Workers Builds clones your repository and runs your commands in CI |
| Worker runtime and deployment configuration | Worker name, entry point, compatibility date and flags, bindings, routes, custom domains, Cron Triggers, runtime variables, and static assets | Your repository's Wrangler configuration file or cloudflare.config.ts. Manage runtime secret values separately. |
When your deploy or Preview command builds and deploys the Worker |
Workers Builds does not use the Wrangler custom build command (build.command) as its CI build command. Set the CI build command in Workers Builds. The deploy command can still trigger a build: wrangler deploy runs build.command if configured. If you configure both commands to build your project, it can build twice.
You can use cf to manage Workers Builds without migrating a Wrangler project. Install and sign in to cf and select the account that owns your Worker.
For a Worker already connected to Builds, replace my-worker with its name and run the following commands. Use jq ↗︎ to extract the Worker tag. Builds identifies the Worker by its tag, not by its name.
worker_tag=$(cf workers get my-worker | jq -er '.id')
cf builds workers get "$worker_tag"The response includes plain build variable values but omits secret values. You cannot use it as a complete backup. To make changes, refer to Update build settings with cf.
Manage build settings in the Cloudflare dashboard under Settings > Build, or programmatically through the Builds API.
Note that when you update and save build settings, the updated settings will be applied to your next build. When you retry a build, the build configurations that exist when the build is retried will be applied.
| Setting | Description |
|---|---|
| Git account | Select the Git account you would like to use. After the initial connection, you can continue to use this Git account for future projects. |
| Git repository | Choose the Git repository you would like to connect your Worker to. |
| Git branch | Select the branch you would like Cloudflare to listen to for new commits. This will be defaulted to main. |
| Build command (Optional) | Set a build command if your project requires a build step (for example, npm run build). This is necessary, for example, when using a front-end framework such as Next.js or Remix. |
| Deploy command | The deploy command lets you set the specific Wrangler command used to deploy your Worker. Your deploy command will default to npx wrangler deploy but you may customize this command. Workers Builds will use the Wrangler version set in your package.json. |
| Preview command | Set the command to run for preview builds. Defaults to npx wrangler preview. Workers Builds will use the Wrangler version set in your package.json. |
| Root directory (Optional) | Specify the path to your project. The root directory defines where the build command will be run and can be helpful in monorepos to isolate a specific project within the repository for builds. |
| API token (Optional) | The API token is used to authenticate your build request and authorize the upload and deployment of your Worker to Cloudflare. By default, Cloudflare will automatically generate an API token for your account when using Workers Builds, and continue to use this API token for all subsequent builds. Alternatively, you can create your own API token, or select one that you already own. |
| Build variables and secrets (Optional) | Add environment variables and secrets accessible only to your build, deploy, and Preview commands inside the CI container (process.env). Build variables are not accessible to your Worker at runtime. For runtime variables, configure vars in your Wrangler configuration file or manage them under Settings > Variables and Secrets. |
To adjust the heap available to a Node.js build process, add NODE_OPTIONS under Settings > Build > Build variables and secrets. For example:
| Name | Value |
|---|---|
NODE_OPTIONS |
--max-old-space-size=4096 |
This sets a 4 GiB heap ceiling without increasing the build machine's memory. This build variable does not change your Worker's runtime memory limit. To select a Node.js version instead, refer to Override default versions.
You can run your deploy command using the package manager of your choice.
If you have added a Wrangler deploy command as a script in your package.json, then you can run it by setting it as your deploy command. For example, npm run deploy.
Examples of other deploy commands you can set include:
| Example Command | Description |
|---|---|
npx wrangler deploy --assets ./public/ |
Deploy your Worker along with static assets from the specified directory. Alternatively, you can use the assets binding. |
npx wrangler deploy --env staging |
If you have a Wrangler environment Worker, you should set your deploy command with the environment flag. For more details, see Advanced Setups. |
npx wrangler deploy --containers-rollout=immediate |
Containers rollout mode for this deploy. Refer to Rollouts. |
npx wrangler deploy --containers-rollout=none |
Deploy the Worker only. Skip container image build/push and instance rollout. |
The Preview command runs when you have enabled preview builds. Preview builds run for branches that are not your production branch.
It defaults to npx wrangler preview, which creates or updates a Preview and produces a Preview URL. Like the build and deploy commands, it can be customized.
If you change this command to npx wrangler versions upload, the build creates a Worker version and Version URL instead of a Preview. Version URLs use the resources configured for that Worker version and do not create branch-isolated resources.
Examples of other Preview commands you can set include:
| Example Command | Description |
|---|---|
yarn exec wrangler preview |
You can customize the package manager used to run Wrangler. |
npx wrangler preview --env staging |
If you have a Wrangler environment Worker, you should set your Preview command with the environment flag. For more details, see Advanced Setups. |
npx cf previews deploy |
Deploy a Preview for a project that uses cloudflare.config.ts. Use cf 1.0.0-beta.18 or later. Earlier versions do not report Preview URLs to Workers Builds, so pull request comments show No Preview URL. |
To configure what variables, secrets, and bindings your Preview uses, refer to Preview settings.
If your repository does not have a Wrangler configuration file, the deploy command (wrangler deploy) will trigger automatic project configuration. This detects your framework, creates the necessary configuration, and opens a pull request for you to review. Once you merge the PR, your project is configured and future builds will deploy normally.
For new Workers Builds projects, preview builds use wrangler preview by default and can use Preview settings for preview-specific bindings, variables, secrets, and resources.
The API token in Workers Builds defines the access granted to Workers Builds for interacting with your account's resources. Currently, only user tokens are supported, with account-owned token support coming soon.
When you select Create new token, a new API token will be created automatically with the following permissions:
- Account: Account Settings (read), Workers Scripts (edit), Workers KV Storage (edit), Workers R2 Storage (edit)
- Zone: Workers Routes (edit) for all zones on the account
- User: User Details (read), Memberships (read)
You can configure the permissions of this API token by navigating to My Profile > API Tokens for user tokens.
It is recommended to consistently use the same API token across all uploads and deployments of your Worker to maintain consistent access permissions.
Static assets and frameworks are now supported in Cloudflare Workers. Learn to set up Workers projects and the commands for each framework in the framework guides:
Workers Builds passes Build variables and secrets to your build, deploy, and Preview commands in CI. Your deployed Worker reads its runtime variables from its runtime bindings, for example env.MY_VAR in a Worker handler. Setting a value in one place does not automatically set it in the other.
The following table compares build-time and runtime variables:
| Variable scope | Available to | Configured in |
|---|---|---|
| Build-time variables and secrets | Build, deploy, and Preview commands in CI, through $MY_VAR in a shell or process.env.MY_VAR in Node.js (for example, NODE_OPTIONS or framework variables such as VITE_* and NEXT_PUBLIC_*) |
Cloudflare dashboard (Settings > Build > Build variables and secrets), cf, or the Builds API (environment_variables). |
| Worker runtime variables and secrets | Your deployed Worker code at request time (env.MY_VAR in your Worker handler or imported from cloudflare:workers) |
vars in your Wrangler configuration file or worker.env in cloudflare.config.ts. Manage secret values separately or use the dashboard (Settings > Variables and Secrets). For Previews, configure Preview settings. |
If both your build step and your deployed Worker require the same value, configure it in both Build variables and secrets and your Worker runtime configuration.
Add build-time environment variables and secrets to make them available to your build, deploy, and Preview commands inside the CI container.
To add build-time environment variables and secrets in the Cloudflare dashboard:
-
In the Cloudflare dashboard, go to the Workers & Pages page.
Go to Workers & Pages ↗ -
In Overview, select your Worker.
-
Go to Settings > Build > Build variables and secrets.
-
Add a variable name and value (or mark it as a secret to mask its value in build logs), then select Save.
To manage build-time variables and secrets programmatically, update production_settings.environment_variables or previews_base_config.environment_variables with the Builds API. Set is_secret to true to mask a value in build logs.
For complete request examples, refer to Builds API reference.
To pass non-secret values to your deployed Worker (env.MY_VAR), declare them in your project configuration. If you use cf to deploy, add them to worker.env in cloudflare.config.ts. If you use Wrangler, add them under vars:
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "my-worker-dev",
"vars": {
"API_HOST": "example.com",
"API_ACCOUNT_ID": "example_user",
"SERVICE_X_DATA": {
"URL": "service-x-api.dev.example",
"MY_ID": 123
}
}
}"$schema" = "./node_modules/wrangler/config-schema.json"
name = "my-worker-dev"
[vars]
API_HOST = "example.com"
API_ACCOUNT_ID = "example_user"
[vars.SERVICE_X_DATA]
URL = "service-x-api.dev.example"
MY_ID = 123Declaring a runtime variable does not make it available to your Workers Builds commands. For sensitive runtime values, use Secrets. To manage runtime variables in the dashboard (Settings > Variables and Secrets) or configure keep_vars with Wrangler, refer to Environment variables and Wrangler source of truth. For Preview-specific runtime variables, secrets, and bindings, refer to Preview settings.
The following system environment variables are injected into the Workers Builds CI container by default (and can be overridden in Build variables and secrets):
| Environment Variable | Injected value | Example use-case |
|---|---|---|
CI |
true |
Changing build behaviour when run on CI versus locally |
WORKERS_CI |
1 |
Changing build behaviour when run on Workers Builds versus locally |
WORKERS_CI_BUILD_UUID |
<build-uuid-of-current-build> |
Passing the Build UUID along to custom workflows |
WORKERS_CI_COMMIT_SHA |
<sha1-hash-of-current-commit> |
Passing current commit ID to error reporting, for example, Sentry |
WORKERS_CI_BRANCH |
<branch-name-from-push-event> |
Customizing build based on branch, for example, disabling debug logging on production |