Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitBucket pipeline is not using cache for npm install

I have a single BitBucket repository containing the code for an Angular app in a folder called ui and a Node API in a folder called api.

My BitBucket pipeline runs ng test for the Angular app, but the node_modules folder isn't being cached correctly.

This is my BitBucket Pipeline yml file:

image: trion/ng-cli-karma

pipelines:
  default:
    - step:
        caches:
          - angular-node
        script:
          - cd ui
          - npm install
          - ng test --watch=false

definitions:
  caches:
    angular-node: /ui/node_modules

When the builds runs it shows:

Cache "angular-node": Downloading
Cache "angular-node": Extracting
Cache "angular-node": Extracted

But when it performs the npm install step it says:

added 1623 packages in 41.944s

I am trying to speed the build up and I can't work out why npm needs to install the dependencies assuming they are already contained in the cache which has been restored.

like image 916
infojolt Avatar asked Mar 19 '18 11:03

infojolt


1 Answers

my guess is, your cache position is not correct. there is a pre-configured node cache (named "node") that can just be activated. no need to do a custom cache for that. (the default cache fails, because your node build is in a sub folder of the clone directory, so you need a custom cache)

cache positons are relative to the clone directory. bitbucket clones into /opt/atlassian/pipelines/agent/build thats probably why your absolute cache-path did not work.

simply making the cache reference relative should do the trick

pipelines:
  default:
    - step:
        caches:
        - angular-node
        script:
        - cd ui
        - npm install
        - ng test --watch=false
definitions:
  caches:
    angular-node: ui/node_modules

that may fix your issue

like image 99
Laures Avatar answered Oct 23 '22 09:10

Laures