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.

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 :)