Setting environment variables toml vs ui

Hi Duncan,

First off, I don’t recommend any pattern of trying to play precedence games between the UI and the toml file; the toml file is ideal to handle ALL variables because it has ability to set a default AND a per-branch or build type context:

# this is the default for all build types not defined specifically below
[build.environment]
  ACCEPT_URL = "/accept”
  CANCEL_URL = "/cancel”

# for the beta branch only
[context.beta.environment]
  ACCEPT_URL = "/staging/accept"
  CANCEL_URL = "/staging/cancel”

Second, you wouldn’t be able to refer to one environment variable from another like that. The values need to be static, and need to be interpolated manually at build time, no matter where you define them. This article has some more details on the successful use of envvars at Netlify:

Specifically, you’ll have to BUILD a value AT BUILD TIME from $URL or $DEPLOY_PRIME_URL plus your path, and you can do contextually different build commands to handle that, something like this (untested but I think it will work)

# default
[build]
  command = `export FINAL_ACCEPT_URL=${URL}${ACCEPT_URL} && do-my-build`
[context.beta.build]
  command = `export FINAL_ACCEPT_URL=${DEPLOY_PRIME_URL}${ACCEPT_URL} && do-my-build`

Let me know how it goes!