Tuesday, 2 May 2017

GitLab CI: How can I reuse installed npm packages between jobs?

I have a GitLab Pages site that uses Gulp for building. My .gitlab-ci.yml file looks similar to this:

image: node:latest

before_script:
  - npm install gulp-cli -g
  - npm install gulp [...and a whole bunch of packages] --save-dev

build:
  stage: build
  script:
  - gulp buildsite
  artifacts:
    paths:
    - public

pages:
  stage: deploy
  script:
  - gulp
  artifacts:
    paths:
    - public

cache:
  paths:
  - node_modules/

Before both the build and pages jobs, the npm install commands are executed (once before each job). Since I have quite a few packages, this usually takes a while.

Is there a way to only do the installs once across the entire build?

I thought that's what cache was supposed to help with, but it still seems like it still redownloads everything.



via user341554

No comments:

Post a Comment