Use gitlab npm cache in gitlab CI
What
We run npm install
multiple times during a CI pipeline.
This always downloads npm packages from the internet, which is not necessary.
We can instead cache the npm modules and avoid downloading them from the internet if they have not changed between job runs. This should make things a bit faster.
We should also be using npm ci
instead of npm install
in CI jobs.
This will speed up CI a bit and save some money.
More infos:
- https://docs.npmjs.com/cli/v9/commands/npm-ci
- https://docs.gitlab.com/ee/ci/caching/#compute-the-cache-key-from-the-lock-file
Results
After comparing some pipeline job runs with and without cache I can't see any improvement to speed. For an example on an audit
job on this branch and another:
(link to job)
(link to job)
It's quite strange, i've always seen good speed improvements when doing this, somehow it's not reflected for this project
Edited by Marwan Zibaoui