Skip to content

Run in CI/CD

Wrangler can be run in a continuous integration/continuous deployment (CI/CD) environment. It is good practice to only deploy your Workers from within a CI/CD environment, rather than running adhoc deployments manually using wrangler deploy. Among other benefits, deploying Workers from within a CI/CD environment makes sure that your Worker is built and deployed within a consistent environment. Deploying Workers from within a CI/CD environment also makes it easier to control access to production credentials.

1. Authentication

When running Wrangler locally, authentication to the Cloudflare API happens via the wrangler login command, which initiates an interactive authentication flow. Since CI/CD environments are non-interactive, Wrangler requires a Cloudflare API token and account ID to authenticate with the Cloudflare API.

Cloudflare account ID

To find your Cloudflare account ID, refer to Find account and zone IDs.

API token

To create an API token to authenticate Wrangler in your CI job:

  1. Log in to the Cloudflare dashboard.
  2. Select My Profile > API Tokens.
  3. Select Create Token > find Edit Cloudflare Workers > select Use Template.
  4. Customize your token name.
  5. Scope your token.

You will need to choose the account and zone resources that the generated API token will have access to. We recommend scoping these down as much as possible to limit the access of your token. For example, if you have access to three different Cloudflare accounts, you should restrict the generated API token to only the account on which you will be deploying a Worker.

2. Set up CI

The method for running Wrangler in your CI/CD environment will depend on the specific setup for your project (whether you use GitHub Actions/Jenkins/GitLab or something else entirely).

To set up your CI:

  1. Go to your CI platform and add the following as secrets:
  1. Create a workflow that will be responsible for deploying the Worker. This workflow should run wrangler deploy. Review an example GitHub Actions workflow in the follow section.

GitHub Action

If you use GitHub Actions, Cloudflare provides an official action for deploying Workers. Refer to the following example workflow which deploys your Worker on push to the main branch.

name: Deploy Worker
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 60
needs: test
steps:
- uses: actions/checkout@v4
- name: Build & Deploy Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

GitLab Pipelines

Refer to GitLab’s blog for an example pipeline. Under the script key, replace npm run deploy with npx wrangler deploy.