Run conditional post-build script

Use case: my company is looking to provide Google with an updated sitemap (curl Google Webmaster Tools - Sitemap Notification Received) after every production build. However, there are times where the sitemap doesn’t change in between builds. Google doesn’t want us to submit the exact same sitemap if there are no changes to it, so I need to build conditional logic to check to see if the sitemap I generate in the production build is different from the sitemap currently live on the site. If it is, I then run the curl command. But there’s a catch: I need to wait until the full site is live to submit the new sitemap, because if I run the curl command during the production build, it’s just going to submit the old sitemap. Somewhat of a chicken/egg situation.

Basically, I’m looking to do the following:

  1. Start my production build.
  2. During the production build, determine if I need to send Google an updated sitemap.
  3. Wait for the build to finish and the site to go live.
  4. If step 2 determines I need to submit an updated sitemap, run a post-build script to update the sitemap. If no sitemap changes are necessary, don’t run the script.

Is something like this possible?

Hi @vigilante

Have a look through the deploy notifications documentation and the settings in the UI under Site Settings > Build & Deploy > Deploy Notifications

Most likely what would work for you is using the Deploy succeeded notification sent to an outgoing webhook which would handle the submission.

Thanks for this. Can I trigger the outgoing webhook conditionally? For instance, I don’t want it to run if during the build I determine the sitemap hasn’t changed. Either that or somehow passing a variable into the outgoing webhook?

I don’t believe so.

I don’t believe that is possible.

What you might do is trigger the webhook regardless and have the script it read the sitemap then store the file hash. Next time the script runs, it can check the sitemap hash against the stored hash and if it is different (so the file has changed) submit the sitemap and store the hash. If it hasn’t, do nothing else.

1 Like

That’s a good idea. I’ll see if I can find a mechanism to store the hash. Thank you!

1 Like