Toggle auto publish via netlify.toml?

Is it possible? Or can I only toggle it via the UI?

Running a monorepo, and would like to be able to toggle autopublish via netlify.toml in various repo subdirectories.

I think the ignore attribute might be your best bet here: https://docs.netlify.com/configure-builds/file-based-configuration/#ignore-builds

Does that seem like it could work for you?

2 issues for me with the ‘stop-build’ vs ‘stop-publish’ approach:

  1. deploy previews aren’t available for built, but unpublished sites (as they are in the UI option of toggling off autopublish). In other words- I’d prefer the autopublish toggle when I want deploy previews.

  2. I couldn’t actually get stop builds to work via netlify.toml.

I tried selecting “Stop builds” in the UI, and the stop build behavior was as expected.

In netlify.toml, however, it seemed to have no effect. I added this to the netlify.toml file:

[build]
ignore = “git diff --quiet HEAD^ HEAD sub_dir/”

My toml file seemed to be read fine otherwise (some redirects, for example).

You can toggle autopublish via our API (see https://open-api.netlify.com/#operation/lockDeploy and https://open-api.netlify.com/#operation/unlockDeploy), but Jen’s suggestion is the best way for you to control based on specific commits automatically. I do not think we’ll change the feature around locked deploys to ever try to be smart; it’s about explicit control.

I also don’t understand this statement:

deploy previews aren’t available for built, but unpublished sites

Deploy previews are completely separate from the autopublishing feature and are built for every commit, if you have us configured to build the branch you are targeting.

So, let’s debug the functionality (or not) of your ignore command. Since you have a monorepo, do you have two netlify.toml’s? I’d think you might need that ignore in the one in the root as well as the one in the base if so.

What does the command you entered return on your repo under the conditions you do and don’t want built, if you run it from the command line locally? (I’m looking for the “exit status” of that command from your terminal - you might be able to do something like:

git diff --quiet HEAD^ HEAD sub_dir/ && echo $?

…to see that status in your shell.

So one thing I should clarify: I’m building locally (pushing changes to netlify via a bitbucket repo), and using the toml for redirects & post-processing settings…

I also don’t understand this statement:

deploy previews aren’t available for built, but unpublished sites

I was trying to contrast the difference between selecting ‘stop build’ in the ui, vs ‘stop publish’ in the UI.

With stop publish, I can build locally, but netlify still processes the updated repo - and I can see the unpublished previews. With stop build (via UI)- then obviously, the repo changes aren’t picked up from bitbucket- so no previews would be available.

So, the option to select stop publish vs stop build is desired (per published repo subdirectory), depending on the scenario.

I’ve tried a few things with the ignore attribute- but no success. I was hoping I could directly give it a boolean value (so I can specify “ignore”, regardless of whether or not there are changes anywhere in the repo). Tried ignore = 0 (to emulate the return code of git diff). Also true / false. This resulted in errors processing the toml.

Having said all that- I have to admit I’m a bit confused about where exactly the toml(s) should be in a monorepo.

I have unique tomls in each published subdirectory. The unique redirect rules for each subdirectory (which represents separate subdomains of a website) are all picked up fine, as are the post-processing directives. Don’t know if the toml’s handle this separately from the build commands- since I’m not actually building in netlify.

A toml in the root of the repo, seems to have no effect on anything (and what would even go in there, when there are unique tomls in each publish directory?

The site(s) in question are about to go into production, so will open an email request (would rather not share the live site details here…).

One new reason for getting the toml ignore working properly: if I make a change in a single repo subdirectory (again, this represents a subdomain of the site)- then all the other sites connected to the monorepo still consume build minutes (even with no content changes in their respective publish directories: all the “build” process is doing, is processing the unique (unchanged from prior commits) tomls in the respective publish dirs).

The docs on the ignore command are currently a bit sparse, but the gist is that it lets you cancel a build depending on the exit code of your ignore command. If the command exits with code 0, build is canceled. If the command exits with code 1, build goes forward- so it is supposed to work something like the boolean you mentioned. Can you try ignore = "exit 0" in one of your tomls?

The example ignore command you shared ignore = “git diff --quiet HEAD^ HEAD sub_dir/” is similar to what we do by default. It says: within the directory subdir/, check if there’s any difference between the last commit and the current commit. If no differences, exit 0, don’t build. If yes differences, exit 1, do build. So of course, the important part there is which subdirectories you define.

Let us know if that helps!