Support Forums

Update environment variables from plugin

PLEASE help us help you by writing a good post!

  • Site name: `reverent-booth-a137d1.netlify.app

I have created a plugin and I want to update/add environment variables through the plugin
I have tried to parse the netlify.toml file and add then update it with our variables to [context.production.environment]

but after the deployment process succeeded the new environment variables not exists and netlify.toml file not get updated

is this the right way to update/add environment variables through the plugin and what are the available other option to update/add env variables?

Hi @eman2008,

You can take a look at:

to see how plugins can react with environment variables in the TOML file.

Environment variables defined in the TOML file aren’t usable in runtime. They can be accessed only during the built. This is what the above plugin attempts to solve.

You can use the API, specifically:

The variables will be listed at build_settings.env

What if want to use the api from the plugin. a token s required
But I only have two options, Personal access token or oAuth2
is there any way I can use the api without personal access token and don’t have to create application and require user permission with oAuth

Hi @eman2008,

A Personal Access Token is a one-time thing that you can acquire from your user settings. You don’t need to create an OAuth2 app for that.

Without the token, you won’t be able to authorise and if we disable authorisation, anyone would be able to change your website.

Okay. I have tried the plugin and I found that I can update/add env variables for platforms with prefix like REACT_APP_ , but normal env variables without prefix are not accessible and I cant read it from my repository

I’m not sure what you mean by normal. Adding Custom Environment Variables | Create React App mentions that React only supports variables ENVs prefixed with REACT_APP.

Quoted from there:

By default you will have NODE_ENV defined for you, and any other environment variables starting with REACT_APP_ .