Home > Blockchain >  Environment variable with netlify.toml file
Environment variable with netlify.toml file

Time:04-13

I'm trying to set a environment variable when I push on a certain branch on my repo (the 'next' branch), the goal is that I want this variable to be defined only in this branch.

I've read the netlify documentation and I have no idea what I'm doing wrong:

https://docs.netlify.com/configure-builds/file-based-configuration/

So I've used the following code in my netlify.toml file:

[context.next.environment]
  SITE_BRANCH = "next"

I also tried [context.next]

My variable never appears in process.env

Does anyone have any idea what I'm doing wrong ? Thanks

EDIT

This is my nuxt.config.js file:

export default {
  publicRuntimeConfig: {
    SITE_BRANCH: 'process.env.SITE_BRANCH'
  }
}

This is my .env file:

SITE_BRANCH=next

CodePudding user response:

Looks like the syntax is more like this (indentation is important)

[context."feat/my-cool-branch"]
  SITE_BRANCH = "next"

This part of the documentation goes more into details.

  • Related