Trigger multi site builds

Hi,

Is it possible to trigger 2 site builds with one git push?

For example, I want to seperate out a main (brochure) site (www.example.com) from a blog style site (blog.example.com) but I also want to be able to show content from the blog onto the main site (like a recent posts feature). I was going to publish an RSS feed of the posts on the blog and use that as the data source for the posts on the main site.

I want to be able to trigger a rebuild of the main site as soon as a new post is published on the blog.

Is this possible?

I am using Gatsby as the SSG with NetlifyCMS on Git.

Hope this makes sense?

Many thanks in advance.

Hi, @Atchett. Here is one solution (and there are likely others as well).

For the site to build after the first, create a build hook:

https://docs.netlify.com/configure-builds/build-hooks/

Then, call that build hook conditionally (meaning, only for successful builds) as part of the first site’s build.

For example, if your build command is this:

npm run build

The new build command would be this:

npm run build && curl https://api.netlify.com/build_hooks/<UNIQUE_ID_HERE>

The && between the two command is the boolean logical “and” in bash. This will guarantee the curl command is only run if the build command is a success.

If there are other questions or if this won’t work for some reason, please let us know.

1 Like

Hi @luke cool solution, I’ll give it a go. Thanks for your help.

FWIW: you can also do this through the netlify web GUI. I have something similar to this today: when I add a new blog post on one site via git push, trigger a build of another site.

First setup a build hook (for the site You want to build when another site does something)

Settings > Build and Deploy > Continuous Deployment

Then in the site you want to trigger a build with, setup a deploy notification (you probably want to do it “on success”)

Settings > Build and Deploy > Deploy Notifications

That’s it! Now netlify will send the webhook for you anytime a site build successfully (which will trigger another netlify site to kick off a build)