Environment Variables
Environment Variables are useful for feeding the build process of your static site information from outside of your site’s code. This allows for information like API keys to be stored and provided securely, rather than in your site’s code as clear text.
Special characters in environment variables
In the environment variable keys, you can only use a-z, 0-9, or underscore (_
). Environment variable values are applied literally, with the exception of parentheses, commas, and double quotes.
Parentheses
Parentheses can cause the build and rollout process to fail. They cannot be used in environment variables.
Commas
Unescaped commas are interpreted as delimiters and cannot be used in environment variables.
- For example:
write_stock,read_orders
will cause the rollout process to fail. - To keep a comma inside a string, escape it with a backslash (
\
) like this:write_stock\,read_orders
— which will be applied aswrite_stock,read_orders
.
Double quotes
Unescaped double quotes are either disregarded or will cause the rollout process to fail.
- For example,
"my_example_variable"
will be applied asmy_example_variable
. - To keep double quotes around a variable, escape them with a backslash (
\
) like this:\"my_example_var\"
— which will be applied as"my_example_var"
. - If double quotes are inside of a string (e.g.
my_exampl"e_text
), the rollout process will fail. - To keep double quotes inside a string, escape them with a backslash (
\
) like this:my_examp\"le_var
— which will be applied asmy_examp"le_var
.
Adding environment variables
Environment variables can be added in the Build settings step when adding a static site or on your site’s Settings page after deployment.
You can reference another environment variable using the ${key}
format. For example, to reference an environment variable with the key DB_PASSWORD
use ${DB_PASSWORD}
.
In build settings
To add environment variables when adding your site, expand the Environment variables section and enter the key-value pairs.
After deployment
To add environment variables after deployment, go to your site’s Settings page, scroll down to the Environment variables section, and click Add environment variable. Add the key-value pairs in the Add environment variable modal/pop-up window.
If you enable pull request previews, you can select whether to use the environment variables in the production environment, preview environment, or both.
Select which environment to use your environment variables for.
If you add or update an Environment variable, you must redeploy the site.
Editing environment variables
You can edit variable names (keys) or values on the Settings page. To edit a variable, click the Edit (pencil) icon, make your changes, and click Save changes.