Automatically trigger a build when a build fails

My builds are failing due to cache issue. But when I make a build with clear cache it succeeds. Can help me and provide a solution where whenever my build fails. Netlify clears the cache and create a new build for me.
Site ID: f0301307-0ada-4f33-a17f-d392506bfd7f

Hey there, @HussnainINS :wave:

Thank you so much for reaching out. I see that you are now having successful builds (hooray!) If you encounter this issue in the future, I suggest you update to the latest version of Gatsby, 4.13.1. Here is a thread where you can read more:

Hi @hillary, My build is not failing due to time out. I just want to know that "Is there any webhook available on Netlify which will be triggered if a build fails "?. thanks you

Sure, there we can contact a webhook for deploy-failed, per these docs: Deploy notifications | Netlify Docs

While you can certainly trigger a deploy programatically with the cache cleared, I think you’d benefit from debugging why your build hangs with cache instead, since build minutes - even for failed builds - cost you, and in case you had a code problem and you’d implemented automatic retries, you’d just keep building over and over forever, and owe us a lot of money. But that’s up to you.

This is the API call to re-attempt a deploy with cache cleared:

POST to https://api.netlify.com/api/v1/deploys/FAILED-DEPLOY-ID-HERE/retry?clear_cache=true

You can see more details about how to understand what our UI does and reverse engineer our API calls which you can use too: [Support Guide] Understanding and using Netlify's API