I am trying to understand and use Netlify’s monorepo support. I cannot produce the build.ignore behavior described in the docs:
An exit-code of 0 indicates that the build should return early.
I’ve setup a PR on my repo to test this with the simplest script possible: exit 0. Here is a snippet from the logs, where you can see that the build continues after running the build.ignore command.
6:35:13 AM: Found Netlify configuration file. Overriding site configuration
6:35:13 AM: Detected ignore command in Netlify configuration file. Proceeding with the specified command: 'exit 0'
6:35:13 AM: Starting build script
Netlify instance names: trainervision.netlify.com and trainervision-amy.netlify.com
I think the exit 0 is exiting the sub-shell and that is why it isn’t working. Would you try making a script which does this instead of running exit 0 directly? For example:
#!/bin/bash
exit 0
This might be saved to a file named exit-zero.sh (with a chmod permission of 700). The build.ignore command would then be the filename “exit-zero.sh” instead.
If this doesn’t work as expected, please let us know.
Also, the other project I’m trying to deploy from this directory (trainervision.netlify.com) is also ignoring the ignore script, but in that case there is no reference of “ignore” anywhere in the logs at all. I bring up the other project because in my PR, I added the script in both the root directory and the subproject directory to see if it either project deployed correctly. Neither did. I’ve also un-linked/re-linked both projects to the GitHub repo.
@hkgumbs, I did some testing and I can reproduce this behavior if the path to the build.ignore script doesn’t match the filesystem location.
I found two root causes:
If the path to the command/script in build.ignore is invalid, the build continues silently assuming a build should continue.
If running a script (and not a command like git diff), the script must be referenced relative to the base directory of the repo (or, possibly, the build directory - I didn’t test that edge case).
So, instead of this:
ignore = "exit-zero.sh"
Try this instead:
ignore = "./exit-zero.sh"
I’ll be filing an issue to about this first root cause above and, instead, have the build system log when there is missing/invalid path for build.ignore. I’ll update this topic once more when this issue is filed.
The second root cause isn’t is a bug, technically. It’s default behavior in a bash shell, but I also believe we should have better documentation about this syntax requirement for scripts in our docs.
So, I have two issues to file and I follow-up here again to let you know when that is done (and to cross-link this topic with the issues).
In the meantime, would you please test adding “./” before any script reference and double-check the path to the script is correct? If that doesn’t solve the issue, please let us know.
Thanks Luke, that worked for the subdirectory site! I’m still having trouble getting the main site (trainervision) to notice the build.ignore flag. I’ve relinked the site to my GitHub repo, but I suspect it’s still not using the new setup. Can you see on your side whether trainervision.netlify.com is setup to support build.ignore? Here’s what I see in the logs where the ignore check typically is:
12:47:21 PM: Preparing Git Reference pull/5/head
12:47:22 PM: Found netlify.toml. Overriding site configuration
12:47:22 PM: Starting build script
The deploy you linked to is from my master branch, but I’ve been experimenting with these settings on the branch called netlify-ignore. To clarify things, I pushed an update to that branch this morning, which seems to clearly illustrate the issue:
The “subdirectory site” deploy, which correctly picks up buld.ignore from netlify.toml
The “main site” deploy, does NOT pick up the build.ignore
The full PR diff
I added a single netlify.toml file in the root directory, a copy of the exit-zero.sh script in the root directory, and a copy of the exit-zero.sh file in the subdirectory (to make sure it would be picked up by both sites).
Sorry to be so slow to get back to you. Still not sure what is happening exactly. Could it be permissions based? Git and any specific file permissions is pretty hard to get reliably correct - could you try modifying to sh ./exit-zero.sh instead of relying on it to be executable after clone?
Unfortunately, that did not seem to help things. The subdirectory site deployed OK, but the main site still does not detect any build.ignore settings: Netlify App.
This site is older than the subdirectory site, so I suspect it’s something to do with the unlinking/relinking on the main site. But I don’t know how to tell what build-image version I’m using.
Hey @apuntovanini and @itswadesh, thanks for letting us know this is an ongoing issue. I was able to reproduce this and have added your reports to an issue that was opened internally about this behavior.
At this point, unfortunately, the only thing I can reliably recommend is setting ignore = "git status" in your netlify.toml file. That should exit 0 and cancel your build.
I acknowledge that this is extremely hacky and hope we’ll have more insight into what’s happening here soon!
I think the issue is that the file permissions for the file don’t allow for the script to be run. This error then returns a non-zero exit code and that determines that a build should still occur.
For example, when I cloned this repo, I had the following results when testing: