Triggering publish with a webhook

Right now, this is how my master branch is deployed:

If I enable auto publishing:

  • Push some changes to master
  • Netlify deploys and publishes the branch (regardless of whether my checks passed)
  • My CI builds the branch and runs tests
  • If the tests pass…
    • The Netlify deploy webhook is called
    • Netlify deploys and publishes the branch again

If I disable auto publishing:

  • Push some changes to master
  • Netlify deploys (but doesn’t publish) the branch
  • My CI builds the branch and runs tests
  • If the tests pass…
    • The Netlify deploy webhook is called
    • Netlify deploys but does not publish the branch

This is what I want to happen:

  • Push some changes to master
  • Netlify deploys (but doesn’t publish) the branch
  • My CI builds the branch and runs tests
  • If the tests pass…
    • A Netlify publish webhook is called
    • Netlify publishes the deployed branch

Is this possible?

Bit of an odd workflow - do you really want us to build the preview and then rebuild it to publish, without any changes?

I’d suggest that instead of calling the webhook after your CI passes, you instead call an API endpoint to publish the existing deploy. Saves you $$ on build minutes too :wink:

https://open-api.netlify.com/#operation/restoreSiteDeploy is the “publish this deploy as production” call, and then if you want to be careful, you can make sure that autopublish is disabled again: https://open-api.netlify.com/#operation/lockDeploy

I’m having a similar problem. I just need to deploy & publish using a webhook, not on push.
To prevent deploying on push I set the production branch to a non existing branch. The problem is that the webhook doesn’t autopublish unless the branch is the production one.

Would be nice to have a querystring option for the webhook to force publish or a way to stop building on git push.

Hi @FDX! Welcome to netlify community.

Yes, this is possible. If you use GitLab or Bitbucket, you can delete the Netlify webhook in the settings for your repo at your git provider. If you are using GitHub, this is a little more involved so let us know and we can help with that.

Hi Laura, I’m having the same issue where I’d like to only deploy and publish after CI passes, and I’m using Github. Is there any way I can disable the automatic deploy on push to master? I don’t see Netlify in my webhooks, since I’m using the Github App.

Since the Github integration uses an app to manage the connections, there won’t be a webhook to remove. There is a setting that can be set on our side but this cannot be managed by you. If you would like me to set it anyways, let me know which site it is.

Yes, that would be great! On my team it’s two sites: upbeat-dijkstra-7703d5 and friendly-newton-ba6d5f.

Done, automatic builds is no longer enabled on those two sites. You can manually trigger builds or using build hooks to start a build.

That worked like a charm! Thanks so much!

Hello!
I am not sure if this the right place to ask, but I would like to deploy only after my CI tests pass, and I could do it using yarn deploy --site #my_site_id --auth #my_token --prod for the production branch.
I can’t find a way to do this for the develop and staging branch though.

Right now all I can find is 2 choices:
1- Set automatic deploys, set branch subdomains and have my code deployed on the correct branch but ignoring my tests
2- Disable automatic deploys and deploy my code to production after my tests pass, but no develop or staging subdomains.

Can you please tell me if there is a way to deploy programmatically to a specified subdomain (branch)?

Hi Fabien, can you please make a new post about this, and tell us your netlify name etc? thank you.

Hi Dennis,

We are in the same situation on our side. We’d like to only trigger a build and deploy from our master branch once our CI have passed our tests. We are using a build hook to do so, but right now our site builds and deploy twice: once automatically when Netlify detects changes on the master branch, and a second time via our CI build hook once tests have passed.

The site is at: admiring-meitner-ad1875

Thanks for you help!
Frank

No problem, just got that enabled for you! Please let me know if it doesn’t work as expected.

Thank you so much, it works great!

Hi,

My netlify username is neoms21 and I’m facing the exact same issue as people here. What I’m assuming that you have to make some setting on your end to stop my sites from auto-publishing on push but from a build hook. I’ve set up one of my repos to be deployed from ‘no_deploy’ and then call the webhook to deploy. It builds fine and deploys the site to master--xxxx.netlify-app.com but doesn’t publish.

Could you please enable that setting for me so that it publishes the site when I call the build-hook on master branch? Could you please do it on both of my sites?

Thanks
M

Hey @neoms21, answered you over here :slight_smile: --> Triggering publish using build hooks

Hello @jen @fool, I am not sure if my issue was answered yet in this thread, but I think it was close.

I currently have neither my Wordpress CMS webhook, https://github.com/staticfuse/gatsby-toolkit, or github webhook auto-publishing onto my website. However, I would like to set the wordpress CMS webhook to auto-publish, whereas I would like the merge from github to not auto-publish. Is this possible with parameters? https://docs.netlify.com/configure-builds/build-hooks/#parameters

nope! You’ll need to implement that logic in either the ignore script or in your build pipeline. We provide the $WEBHOOK_* environment variables during build:

… and even if you don’t build two different branches (which is the pattern my next link is about), you can use a similar pattern as we describe in this article around doing conditional builds based on that incoming build data, instead of based on the branch or commit type: