Jenkins: Excluding Directories when Cleaning Workspace

For most projects, I recommend that nightly builds start with a completely clean workspace.

However, there are certain cases where cleaning is not feasible - repos including large artifacts (e.g. specific toolchains) or numerous git-lfs artifacts. You can destroy bandwidth and increase build time by re-downloading these files for every build.

Using jenkins, you can specify directories to exclude from the "clean workspace" requirement. However... you need to also exclude the .git directory.

If you fail to exclude the .git directory from workspace cleanup, the repository will no longer be a valid git repo and jenkins will re-clone the repository. So make sure there is always a .git in your exclude list if you are keeping some files around.

N.B.: Excluding .git is also required for submodules you are excluding files in!