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.