CI/CD: Deployment Pipelines for Cloudflare Workers
Automate your Cloudflare deployments with GitHub Actions and Wrangler. Learn to manage deployment keys, secure secrets, and streamline your delivery pipeline.

Previously in this course, we covered CI/CD: Automated Testing, where we ensured our Worker logic was sound before deployment. Now, we're taking the final step: automating the deployment process itself so that every push to your repository results in an updated, live application.
In the world of DevOps, relying on local machine deployments is a recipe for "it works on my machine" syndrome. By moving to a CI/CD pipeline, you ensure that every deployment follows the exact same process in a clean, isolated environment.
The Anatomy of a Deployment Pipeline
A deployment pipeline for Cloudflare Workers consists of three main parts:
- The Trigger: An event in GitHub (usually a push to the
mainbranch). - The Environment: A virtual machine provided by GitHub Actions.
- The Execution: Running the
wrangler deploycommand using stored credentials.
To achieve this, we need to move our local authentication credentials into the cloud.
Creating a Cloudflare API Token
Wrangler uses an API Token to authenticate with your Cloudflare account. Because we don't want to hardcode this token in our repository, we use GitHub Secrets.
- Go to your Cloudflare Dashboard.
- Navigate to My Profile > API Tokens.
- Create a Custom Token. Grant it
Cloudflare Workers: Editpermissions and restrict it to your specific account/zone if possible. - Once created, copy the token. Do not share it!
Configuring GitHub Secrets
Now, we need to store this token securely so our GitHub Action can access it.
- In your GitHub repository, go to Settings > Secrets and variables > Actions.
- Click New repository secret.
- Name it
CLOUDFLARE_API_TOKENand paste your token as the value. - Add another secret named
CLOUDFLARE_ACCOUNT_IDwith your Account ID (found on your dashboard's overview page).
Writing the GitHub Action
Create a file in your project directory at .github/workflows/deploy.yml. This YAML file defines the automated workflow.
YAMLname: Deploy Worker on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install dependencies run: npm install - name: Deploy to Cloudflare uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
This workflow triggers whenever you push to main. It checks out your code, installs your project dependencies, and uses the official Wrangler Action to deploy your Worker. For more advanced workflows, you can explore Production Deployment: Automating Secure CD Pipelines to handle environment-specific configurations.
Hands-on Exercise
- Commit your workflow: Add the
.github/workflows/deploy.ymlfile to your repository and push it tomain. - Observe: Go to the "Actions" tab in your GitHub repository. You should see the job running immediately.
- Verify: Once the job turns green, visit your Worker URL. You should see your latest code live on the edge.
- Refine: If your project grows, consider implementing Manual Approval Gates: Controlling Production Deployments to prevent accidental production pushes.
Common Pitfalls
- Expired Tokens: Cloudflare API tokens can expire. If your pipeline suddenly fails with 401 or 403 errors, check the token status in the Cloudflare dashboard.
- Missing Bindings: If your Worker relies on R2 or D1, ensure your
wrangler.tomlis correctly configured. Thewrangler-actionrespects yourwrangler.tomlfile, so ensure it doesn't contain local-only settings that break in CI. - Permissions: Ensure the GitHub Action has permission to write to your repo if you are performing tasks like automated version bumping.
FAQ
Q: Can I deploy to a staging environment first? A: Yes. You can define multiple jobs in your workflow or use separate branches. See Staging Environments: Mastering Deployment Targets in CI/CD for a deep dive on managing multiple environments.
Q: Should I store my API Token in the code? A: Never. Always use GitHub Secrets. If you accidentally commit a token, revoke it in the Cloudflare dashboard immediately and rotate your keys.
Q: Does this work for Pages as well as Workers? A: Yes, the process is nearly identical, though you might use a different action or command for Cloudflare Pages.
Recap
We've successfully moved from manual deployments to a professional CI/CD flow. By using GitHub Actions, we've ensured that our deployment process is repeatable, secure, and fully automated.
Up next: Performance Auditing — we'll look at how to measure the real-world impact of our code changes and ensure our edge deployment is as fast as possible.
Work with me

CI/CD Pipeline & Docker Containerization
Ship with confidence: automated CI/CD pipelines and Docker setups so every push is tested and deployed — no more manual, error-prone releases.

Custom Email & File Storage System on Cloudflare (Google Workspace Alternative)
Your own private email + file storage suite on your domain — unlimited mailboxes, no per-seat fees. A self-owned Google Workspace alternative for a flat ~$5/month.

