Skip to content

CI build: How to cache different paths by different keys?

Hello,
I'm building a hakyll page and using a .gitlab-ci.yml quite similar to the official demo one. I'm having issues with build times, and I would like to ensure that the .stack directory is cached globally while hakyll's _cache should be cached on a per-branch basis.

I've checked the documentation and it states "By default the caching is enabled per-job and per-branch." which seems to suggest that by default there's a default

key: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME"

on every cache directive?

Now I am hoping to do something like

pages:
  cache:
    - key: "$CI_BUILD_NAME/stack"
      paths:
        - .stack
    - key: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME"
      paths:
        - _cache

Is that possible?

And if not, is there some work-around? I suspect it should be possible by splitting pages into multiple jobs, one doing the compilation and one the creation of the pages, but I guess I somehow would need to extract the current site executable (via --copy-bins) and make it an artifact so that I can execute it in the next job… Can someone confirm this course of action?