7

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.

infojolt
  • 5,244
  • 3
  • 40
  • 82

1 Answers1

12

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

Laures
  • 5,389
  • 11
  • 50
  • 76
  • Does the preconfigured cache not look in node_modules rather than the subfolder? – infojolt Apr 06 '18 at 15:21
  • 1
    after reading the documentation aggain (https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html) i think your initial Approach was correct but you should use a relative path (take the leading / away) as your clone path is not at top level. the default node cache does not work because your project uses a subfolder. i will update my answer – Laures Apr 12 '18 at 13:09