Only "npm install" in GitLab CI when updating package.json

I use GitLab CI for the project, and the first step of the process is npm install . I cache node_modules to start the same work more quickly later, and also define them as build artifacts to use them at later stages. However, even if I cache node_modules and update by calling npm install each time the install_packages job is complete, it takes a lot of time, as the command goes through all package.json and checks for package updates, etc. (suppose).

Is there a way to only run npm install in the install_packages job depending on some condition? More specifically (which, in my opinion, would be a better solution), has package.json changed or not since the last build?

Below is the relevant part of my .gitlab-ci.yml file:

 image: node:6.9.1 stages: - install - prepare - deploy install_packages: stage: install script: - npm prune - npm install cache: key: ${CI_BUILD_REF_NAME} paths: - node_modules/ artifacts: paths: - node_modules/ only: - master - develop build_and_test: stage: prepare script: #do_stuff... deploy_production: stage: deploy #do_stuff... deploy_staging: stage: deploy #do_stuff... 
+13
source share
2 answers

Is npm installed with the --cache option? I heard this problem with several Gitlab CI runners that people have, and this is the solution most often.

Hope this helps!

0
source

Just use only:changes doc flag

Work will be:

 install_packages: stage: install script: - npm prune - npm install cache: key: ${CI_BUILD_REF_NAME} paths: - node_modules/ artifacts: paths: - node_modules/ only: refs: - master - develop changes: - package.json 

Another point: did you install the cache correctly? Read this: https://docs.gitlab.com/runner/configuration/autoscale.html#distributed-runners-caching https://docs.gitlab.com/ee/ci/caching/

0
source

Source: https://habr.com/ru/post/1012351/


All Articles