Run Wrangler in CI/CD
To run Wrangler in a continuous integration/continuous deployment (CI/CD) environment, you must provide a Cloudflare API token and account ID.
Create a Cloudflare API token
To create a token:
- Log in to the Cloudflare dashboard.
- Select the user icon on the top right of your dashboard > My Profile.
- Select API Tokens > Create Token.
- Select Use template next to Edit Cloudflare Workers. All templates are prefilled with a token name and permissions. You also need to modify the account and zone resources you want assigned to the token.
- After editing your token, select Continue to summary and review the permissions before selecting create token.
- Create an
.env
file in your project directory and setCLOUDFLARE_API_TOKEN
as the key and your token as the value.
CLOUDFLARE_API_TOKEN=<YOUR_API_TOKEN_VALUE>
You can also inline the value directly with the npx wrangler deploy
command. For example: CLOUDFLARE_API_TOKEN=XXX npx wrangler deploy
.
Refer to API Token for more information on set up.
Account ID
You have three options for telling Wrangler which Cloudflare account to use:
- If there is only one account associated with the API token, then the account ID is inferred automatically;
- Add the
account_id
to the project’swrangler.toml
file (for example,account_id = "12345679"
). - Add the account ID to the
CLOUDFLARE_ACCOUNT_ID
environment variable.