Build & Deploy via webhook only

Hi,

I can’t seem to find an option to only build & deploy via a webhook. Is it possible?
This means that i do not want to build/deploy automatically via a git commit/push.

Or an option to only build via a git commit/push and build/deploy via webhook would also be fine.

Thanks!

Hi @lkniep,

You can change the publish branch in your build and deploy settings to something that you would never use, like “this-will-never-deploy”. Or if you are on gitlab or bitbucket you can remove the build webhooks from the repo.

Hi @futuregerald

That was what i did in the first place. Setting ‘Production branch’ to something which does not exist.
But if a build gets triggered via a webhook(which will trigger a build for master) you can’t see it back in the ‘production deploys’ overview… Because the ‘production deploys’ overview shows an overview about the branch which does not exist…

Yes, that’s a drawback with the workaround. You’ll want to view your deploys directly on the deploy page, instead.

This means i can’t use badges for build status right?

Is the option to disable auto build/deploy on commit something that will come in the near future?

there is already a feature to do that - if you include [skip ci] in your commit message, we won’t build. I understand that you probably don’t want to prefix all your commit messages with that, but it is possible.

I don’t think we have plans to change the “how you specify what we build” setup in other ways anytime soon, but we do have an open feature request to allow badges for other branches to which I’ve added this thread for followup in case we ship it.

In the meantime there are some other potential workarounds for you:

  1. locked deploys - we still build everything, but never autopublish it: https://www.netlify.com/docs/locked-deploys/ . This is what we use to disable autopublishing e.g. before a major release. You can publish an existing deploy via our API
  2. give your build script some other smart logic to check if this one is an intended build and build it only in case it matches some pattern (e.g. only build merge requests)
  3. try filtering the webhooks sent to netlify using a service like zapier (“oh, that’s a PR that says WIP in its commit message; don’t forward this one to Netlify!”)
2 Likes

@futuregerald What do you mean by “publish branch”? Which build and deploy section is that setting under?

@lkniep But surely if you’ve changed the production branch to a non existent branch, then the webhook will attempt to trigger the non existent branch (instead of master) and then fail? Or am I misunderstanding something?

Hey @mjgs,
You can set your production branch here (where SITE-NAME is your own :slight_smile: ): https://app.netlify.com/sites/SITE-NAME/settings/deploys#deploy-contexts

The suggestion here is to keep the build via git push, but not publish that deploy.

Since the OP wrote in, we have launched Locked Deploys, which may also be useful for you:

Let us know if this helps or if you have any other questions!

I think this related to this question: Triggering publish with a webhook
and this post: [Support Guide] How can I disable automatic git deploys?.

I was trying to only build/deploy by adding the build hook to my pipeline. Adding it to the pipeline as is resulted in double builds (triggered by push AND pipeline). Renaming the production branch with a bogus name didn’t work for me because I wanted it to automatically publish on my actual main branch. I ended up…

  1. Creating a build hook and leaving my production branch name the same
  2. Disabling the webhook in my repo (automatically added by Netlify)
  3. Adding the build hook to my pipeline

Hope this helps someone!

Curious if anyone has some idea of contrasting this idea of setting the publish branch to some bogus branch name vs unlinking github from the site. Just curious of the pros/cons.

I am looking for the best way to continue with manual builds via CLI and CI/CD, while having the abiility to lock the production build to a particular deploy, and publish newer or revert to older deploys via the deploys page UI when needed. Currently we have builds turned off, so we cannot manually publish a deploy via the UI.

Adding one more possibility to the mix here: a currently undocumented behavior of our ignore command is that it won’t run for builds triggered by webhook… but it will run for builds triggered by a push to Github. So if your netlify.toml is:

[build]
  ignore = "exit 0" 

this will cancel all builds triggered via Github push. But webhook builds will succeed.