Can't access Build environment variables

In the /settings/deploys#environment for my project I am settings env variables as follows:

It worked only for one deployment. All the subsequent deployments showed values for GATSBY_URL vars as $URL rather than the website url.

What am I missing here?

You cannot “stack” variables like that unless you do some very special parsing. We don’t interpolate for you, so as you see, you’ll get the string literal rather than the interpretation of an interpretation. Kinda like if you set $vara="$varb" - it’s a string :slight_smile:

You could try something like this:

  1. create a shell script for your build
  2. in the shell script, use your normal build command but first set up the environment.

I haven’t tested this but something like this may work:

npm run build

Effectively, since in our UI those are strings, you need to programatically dereference or interpolate your variables. What I suggested may or may not work but something like that could :slight_smile:

All I need is to access the site url (be it a preview or my custom domain) during the build stage so I can provide an absolute path for the og:image instead of /img/og-image.jpg @fool

OK, then use $DEPLOY_PRIME_URL or $DEPLOY_URL or $URL directly (note that you need to do something to use them as described here:

…or do the trick I mentioned to set the GATSBY_* variables which you don’t have to “use” as described in that article :slight_smile: