Deploy with branch name - including correct ENV data

Hi everyone!

I would like to deploy my frontend app to Cloudflare pages.

We’re using different branches for develop, test, staging and production. (dev/test/stag/pro)

We want readable preview links for our customers, so we would like to create different URL’s with de different branches connected to it.

I know how to create the different URL’s in the custom domain section, and I know Cloudflare passes the branch name in front off the created link.

But but the problem is, all the preview deployments uses the same ENV data.

So no matter which branch you deploy, it’s all created with the ENV from the dev environment variables.

The production deployment has it’s own ENV section, so that one will work.
That also applies for the dev branch and deployment, that on will work as well

But how do I get the TEST and STAGING environment work without having a separates ENV section in Cloudflare?

Of course you can pass .env files within your deployment, but .env should not live in the repo at all, so that’s not an option.

Kind regards,

I’d checkout Set build commands per branch · Cloudflare Pages docs for how to do things per env

Hi Walshy,

Thank you for your reply.

I’ve seen the document you’ve send, and I can imagine running different scripts for different environments/branches.

But we are keeping the environment variables in vault environments such as Hashicorp Vault/Doppler/Infisical. These services need a place in Cloudflare Pages where they can pass the ENV variables into. Now, there are just 2 places in Cloudflare Pages. Preview and Production.
These are connected with the environments in these services: Develop/Production

How can I pass the ENV variables from the TEST env/branch into the TEST preview deployment in Cloudflare pages?

Anybody any other thoughts on this?