0
votes

I'm trying to configure my gitlab ci to use multiple stages but it just doesnt seem to work. Any idea what needs to be corrected here?

gitlab-ci.yml

cache:
  key: "NPM_MODULES_CACHE"
  paths:
    - $(pwd)/node_modules/

stages:
  - install
  - test
  - build

Install:
  stage: install
  rules:
    - if: '$CI_COMMIT_BRANCH == "aws/pipeline-test"'
  script:
    - npm install

Test:
  stage: test
  script:
    - npm run test

Build:
  stage: build
  rules:
    - if: '$CI_COMMIT_BRANCH == "aws/pipeline-test"'
  script:
    - npm run build
  artifacts:
    paths:
      - dist/ 

First stage execute fine but second and third stages are not executing at all. enter image description here

ADDITIONALLY: how can i configure this where 'install' and 'test' stages are executed on code commit from any feature branch, BUT 'build' stage executes only after changes are merged to master branch?? ideally without running npm install between stages

Any help is super appreciated :)

1

1 Answers

0
votes

This answer here https://stackoverflow.com/a/69744855/11129608 should solve all of your issues

Please also refer to the gitlab-ci docs, they're really good!

https://docs.gitlab.com/ee/ci/caching/#cache-nodejs-dependencies