Conditional build behavior using netlify.toml & configuration variables?

Hi!

I’m trying to find a way to condition my build using configuration variables. More precisely I want to copy either robots-production.txt or robots-dev.txt to robots.txt if the URL is equal to mysite.com. I want to avoid creating a special branch and since the url needs to be static using deploy preview is not an alternative.

Is it possible to achieve this using netlify.toml?

[???]
command = “mv robots-production.txt robots.txt”

[???]
command = “mv robots-dev.txt robots.txt”

Any suggestions on how to write the condition logic would be highly appreciated!

How are you checking for the URL?

In any case, I don’t think netlify.toml would help you here and you might have to write either a bash script, or a Node.js script to do what you need.

URL is listed under “Deploy URLs and metadata” in “Build environment variables” in the docs. That should give me access to the url in netlify.toml but I can’t figure out the syntax.

No but I still don’t understand, why would your URL be different across builds? Are you deploying 3 sites from the same repo?

Two different. One is production and the other is for Storyblok preview. The latter should not be indexed and therefore I need to use different robots.txt for the different builds. I could solve this by using a different branch for the preview, easy to set up in netlify.toml but I want to avoid this.

Does the “no” mean that I cannot access the URL variable in netlify.toml?

No need to check conditions then, just set a different build command for each site in your site settings instead of netlify.toml.

Perfect solution, thank you!

If anyone stumbles over this the build command would look something like this:

npm run generate && cp robots-dev.txt dist/robots.txt