Is it possible to access the environment variable DEPLOY_URL inside of Gatsby?

I’m trying to set up an image component using Imgix which works great for URLs sourced from other locations, like Shopify for example.

However with Gatsby, I have a bunch of images that are static and local to the project, so the only URL I’ve been able to output is a relative one.

My goal is to detect when the build/deploy has happened through Netlify in production, and append the relative URLs I have access to in this way:


Which would result in an image URL that Imgix can pick up, like this.

Ideally I’d like this to happen only in production and specific to the hashed deploy URL.

But I’m pretty stuck on how to pass Netlify read-only variables into Gatsby.

hi there proton,

I’m going to get the :eyes: of a gatsby pro on this - we will have a chance to talk to them next week, i believe - and we can circle back with you here when we know more. thanks for your patience.

Awesome @perry , thanks and really looking forward to what you find!

hi @proton , i spoke to our most knowledgeable dev and we brainstormed the following - you could try doing something like this:


GATSBY_DEPLOY_URL=${DEPLOY_URL} gatsby build as your build command MIGHT do what you are hoping to - injected the deploy url into that environment variable so you can re-use it as you wish.

this is untested code, so, i have no guarantees it will work, but it is something to try! If this doesn’t work, we might be out of ideas, but do let us know.

Thanks, I gave it a shot but it comes through as undefined unfortunately. Will continue searching for the answer here

sorry we couldn’t be of more help! if you figure out a way to do this, please do let us know.