Conditional Build using env vars?

I have a monorepo with several sites, which are build using Netlify, I created several Sites in Netlify account to deploy them separately.

testing repository here:

they deploy to those URLs:
https://monorepo-site-one.netlify.app/
https://monorepo-site-two.netlify.app/

unfortunately, because of the way monorepos are used, they both trigger a build all the time.

I tried to figure out if a build is really necessary by adding this

[build]
  ignore = "git diff --quiet master workspaces/${SITE}/"

I setup corresponding env vars in each site… but it looks like they are not available during this step of the build. is there anyway to have one netlify.toml to rule several builds?

important in my case:

  • there is a shared folder in my repository, if this is changed, both sites should start building
  • if only siteOne or siteTwo has changes, the build should only trigger to corresponding sites build

the docs mention this:

However, the following workflow can be used to substitute values in the file with environment variable values, assuming you are only trying to change headers or redirects .

which sounds like they are not accessible during this part of the build steps

Hello @Kevin_Forster :wave:

Thank you so much for reaching out with this question! My apologies for the delay in response time.

I wanted to reach out to confirm that we are working on getting some additional information and insights for you. In the interim, please let us know if the status of your question has changed or if you have found new information that pertains to your original question.

Hey @Kevin_Forster,
I think you should be able to access the subdomain during build (in the ignore script, which is bash- elsewhere, you’ll access the env vars differently!) like this: $SITE_NAME, so the full ignore command would be:

[build]
  ignore = "git diff --quiet master workspaces/$SITE_NAME/"

If you’re looking for a different read-only env var, you can pick from ones listed here:

Let us know if that works for you!

1 Like