I think it should work to use make together with caching the build artifacts.
-
By caching the build artifacts, the old artifacts are present in the new build job. See: Caching in GitLab CI/CD | GitLab
-
Make rebuilds them (and updates the cache) if a dependency had changed.
For this to work correctly, see Makefiles and GitLab CI stages
This way, the ‘build’ job runs, but it only rebuilds artifacts as needed.
If you work with multiple branches, use caching with fallback cache keys in order to reuse artifacts from your default branch for other branches. See: Caching in GitLab CI/CD | GitLab
This way, cached artifacts from the main branch can be used as base for other branches, but no artifacts produced on those branches end up in a branch where it does not belong.
This is a bit of a misuse of the caching feature, as it is not meant to be used for build artifacts.
Disclaimer: I haven’t tried this approach yet.