Meet GitLab's CI cache!
You can use it e.g. to share your node_modules
folder. Running npm install
once the dependencies are there, will just update if needed.
Here you have an example project with Angular of using:
cache:
paths:
- node_modules/
Where you can compare the execution time of the 2 stages (https://gitlab.com/solidgear-projects/GitlabCI/pipelines/11759264):
- First stage: 8 minutes 25 seconds
- Second stage: 56 seconds since after "
Successfully extracted cache
"
Note that cache
is only to share stuff between jobs (you mentioned you have one for build and one for deploy).
To share stuff between different builds (pipelines), I'd recommend you to read on https://about.gitlab.com/2017/07/11/dockerizing-review-apps/ which gives some hints on how to use docker images to bundle all your app's dependencies in a base image and reuse it in the future for your builds. e.g.
build_base:
stage: build
image: docker
services:
- docker:dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD registry.gitlab.com
- docker pull registry.gitlab.com/your-name/your-project:base
script:
- docker build -t registry.gitlab.com/your-name/your-project .
- docker push registry.gitlab.com/your-name/your-project:base
when: manual