Gitlab-CI avoid unnecessary rebuilds of react portion of project

Viewed 186

I have a stage in my CI pipeline (gitlab-ci) as follows:

build_node:
  stage: Build Prerequisites
  only:
    - staging
    - production
    - ci
  image: node:15.5.0
  artifacts:
    paths:
      - http
  cache:
    key: "node_modules"
    paths:
      - ui/node_modules
  script:
    - cd ui
    - yarn install --network-timeout 600000
    - CI=false yarn build
    - mv build ../http

The UI however, is not the only part of the project. There are other files with their own build processes. So whenever we commit changes for only those other files, this stage gets rerun every time, even if nothing in the ui folder changed.

Is there a way to have gitlab cache or otherwise not rebuild this every time if there were no changes? Any changes that should trigger a rebuild would all be under the ui folder. Just have it use the older build if possible?

1 Answers
Related