Triggering Netlify from a specific GitHub branch

answered
#1

I am triggering my Netlify build from pushes to a GitHub repository that is different than the one that the site is build off. GitHub does not support triggering webhooks for a specific branch, so currently it’s pushing notifications to Netlify on every branch. I’d love to find a way to limit these builds to only the ones for a specific build. Is there a way we can achieve this?

Feature requests - what do you already love, what could be better?
#2

Hey cbetta

You could setup a netlify function as your webhook endpoint.

In that function, you can check the github webhook payload and verify the branch is the correct one and then ping the netlify build URL if it matches.

Here is a function example that is triggering builds from dropbox https://github.com/chaseadamsio/chaseonsoftware/blob/3f181cd88417dd002c90fff36afb75fe46357e50/src/_netlify-functions/dropbox-webhook.js#L31-L43

You can alter that code to instead receive the github webhook post. In your github webhook setting you would point to the netlify function URL (something like mysite.com/.netlify/functions/function-name)

From https://functions.netlify.com/examples

1 Like
Gatsby/Github cache issue when fetching remote sources
#3

I actually ended up doing this before you mentioned this and it indeed works! Thanks for the tip.

I do feel that, although it’s a solution, it’s also costing me function calls I’d rather use for production features. I’d love to see a solution for this come to the platform some time.

#4

hey there, if you haven’t already, this might be a great thing to write up in this thread on features you’d love to see.