How can you tie builds to environments

Hi there.

I am working on a client project and we are utilising environments for development sandboxes. We have three environments - (primary, dev-sandbox and uat-sandbox for client testing). We are using Gatsby (using gatsby-source-datocms plugin for Gatsby) and have four build triggers to Netlify sites(dev, uat, preview and production).

I understand that deployments are based off branches so I might be misunderstanding this conceptually, but I am wondering how I can tie my environments the build triggers. eg a dev build trigger will use the content on dev-sandbox, and so on.

I think this requires me to pull the environment details from Dato into Gatsby but not sure. Any advice would be much appreciated

Thanks

Hello @richard.sando

Build triggers aren’t environment specific, as they just send a webhook to the desired endpoint (Netlify on your case) to initiate a build, that is based on the code of the project that is hosted in that Netlify instance.
So only inside of the code of the project that is hosted on netlify you can choose from which environment to pull from:

when you create the DatoCMS client (if you are using the CMA) you can specify as such: Using the NodeJS client - DatoCMS
Or, if you are using the CDA you can specify following this: Content Delivery API - API Endpoints - DatoCMS Docs

Thank you for the response.

I’m using gatsby-source-datocms to pull data from Dato. Is it possible to simply specify the Dato environment within the options of this plugin? Changing the options of this plugin doesn’t seem to be changing the environment to that which is defined, the site keeps building from the primary environment.

The project currently does not utilise either of the above APIs.

@richard.sando no problem at all!

You can see how to set up the environment you are using on gatsby-source-datocms on this documentation page: gatsby-source-datocms | Gatsby

Specifically here:

@m.finamor The data seems to be still pulling from the primary environment even after setting this config to the other environments. Any assistance would be greatly appreciated

@richard.sando could you invite me to the project repository so i can take a closer look at what could be happening? I’m @marcelofinamorvieira on github :slight_smile:

We’re using bitbucket as our source control - I have sent you an invitation to the repository to your email. Many thanks

@richard.sando Thank you!

Just one thing missing, what is the name of your project inside Dato? (or just link me to the project login page :slight_smile: )

https://det.admin.datocms.com/sign_in

@richard.sando Thank you!

Unfortunately i’m unable to run yarn install or npm install in your project, as it seems to have some conflicts (even with --force or --legacy-peer-deps)

Is there something i’m missing?

Hi @m.finamor we are using an older version of node - v12.16.1. This may be what is causing the conflict errors

1 Like

Hello @richard.sando

Thank you, using that node version i was able to find the problem.

You are currently running gatsby-source-datocms on the version 2.1.22 while the current version is 4.0.1

And i’m fairly certain that 2.1.22 didn’t have support for the environment change as per the current documentation.

So you’ll have to update the package to a more recent version (preferably the most recent one, as it has several fixes and performance improvements) to change the environment unfortunately.

Ah that makes sense. Thanks so much for your support @m.finamor !

1 Like