Can't use env from cloudflare in deployed workers with ci/cd

My Wrangler GitHub Action isn't applying environment variables set in the Cloudflare dashboard to deployments made by uploading the dist folder. The Action seems to require a build step first, but even after building, the uploaded dist content doesn't access the dashboard-configured environment variables.
jobs:
deploy:
env:
CLOUDFLARE_ENV: staging
MY_SECRET: ${{ secrets.MY_SECRET }} // I've already added to cloudflare dashboard but can't access from my deployed version

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions

- name: Build project
run: bun run build // Do I really need to build first?

- name: Deploy Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
jobs:
deploy:
env:
CLOUDFLARE_ENV: staging
MY_SECRET: ${{ secrets.MY_SECRET }} // I've already added to cloudflare dashboard but can't access from my deployed version

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions

- name: Build project
run: bun run build // Do I really need to build first?

- name: Deploy Worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
2 Replies
Hello, I’m Allie!
GitHub Actions don’t have access to variables set on the Cloudflare Dashboard If your secret is on the dashboard, you just deploy without it, and it will be present
Zwel
ZwelOP5mo ago
@HardlyWorkin' thanks for you answer.But It can't access the env from the dashboard in my deployed website with github actions. What I did is that I build the project inside GH action and upload the dist folder with wrangler. I've already setup env in dashboard, but can't access via my deployed version. It works when I deploy from local-machine using command like "wrangler deploy" from terminal. But not in GH actions. In the case of local-deployment with coludflare-vite-plugin, I don't even need to set env in dashboard. How it can be done? When it comes to "manual-deployment", I think cloudflare let uploading the "asset-folder" with already injected env. For the manual deployment using "wrangler/action", it just deploy instead of building the app on the cloudflare, So I think I can't bind any env until I "injecting env with manual-build" before deploy. So that, I will always need to add "github-repo-secrets" for every secret-env of my app for the build-process to deploy manually.

Did you find this page helpful?