Set up environment variables for your static sites.
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.
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 can cause the build and rollout process to fail. They cannot be used in environment variables.
Unescaped commas are interpreted as delimiters and cannot be used in environment variables.
write_stock,read_orders
will cause the rollout process to fail.\
) like this: write_stock\,read_orders
— which will be applied as write_stock,read_orders
.Unescaped double quotes are either disregarded or will cause the rollout process to fail.
"my_example_variable"
will be applied as my_example_variable
.\
) like this: \"my_example_var\"
— which will be applied as "my_example_var"
.my_exampl"e_text
), the rollout process will fail.\
) like this: my_examp\"le_var
— which will be applied as my_examp"le_var
.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}
.
To add environment variables when adding your site, expand the Environment variables section and enter the key-value pairs.
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.
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.