How do I set secrets and environment variables for specific environments in the Workers dashboard?

I'm currently migrating a Pages project to Workers, and I'm unsure how to configure secrets or environment variables for specific environments—like production or preview—within the Workers dashboard. In the Pages settings, there's a "Choose environment" dropdown that makes this straightforward, but I can't find a similar option in the Workers settings.
3 Replies
Mikkel Svartveit
I'm having a similar issue. I know that you can specify per-environment variables in wrangler.jsonc, and also upload secrets to a specific environment using Wrangler CLI. However, I see no way to do so in the dashboard, and I'm also not able to specify build-time environments for specific environments at all. This is blocking me from migrating to the new Workers. Made a post about the build-time variables here: https://discord.com/channels/595317990191398933/1359464622188531753
Pawel
PawelOP2w ago
Also the same goes for bindings. If I want to use let's say different D1 database between production and preview I can't do it currently with Workers, but it's possible in Pages. https://developers.cloudflare.com/workers/static-assets/migrate-from-pages/#preview-environment states that:
Unlike Pages, Workers does not natively support defining different bindings in production vs. non-production builds. This is something we are actively exploring, but in the meantime, you may wish to explore using Wrangler Environments and an appropriate Workers Build configuration to achieve this.
so it's seems there is active development to support it
Cloudflare Docs
Migrate from Pages · Cloudflare Workers docs
A guide for migrating from Cloudflare Pages to Cloudflare Workers. Includes a compatibility matrix for comparing the features of Cloudflare Workers and Pages.
Mikkel Svartveit
Good find, that's nice to know. I think I'll hold off on migrating from Pages for now

Did you find this page helpful?