I am building a buildspec file for my AWS code build but I don't know at which phase I need to add NPM run test and if the test fails, I expect build to stop.
Here is the buildspec I have created:
version: 0.2
env:
parameter-store:
ECOSYSTEM_CONFIG: "Ecosystem-config"
ENV: "backend"
phases:
install:
runtime-versions:
nodejs: 14
commands:
- npm install
- npm install pm2 -g
- npm install nodemon -g
pre_build:
commands:
- echo $ENV > .env.dev
- echo $ECOSYSTEM_CONFIG > ecosystem.config.js
build:
commands:
- pm2 start ecosystem.config.js
artifacts:
files:
- '**/*'
cache:
paths:
- node_modules/
I am expecting my buildspec to run and if the test cases fails, the process stops.
It does not matter where the test command is placed. Instead, you may just need to use
on-failure: ABORTto instruct the build to stop when the test command fails. For example,https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.phases.on-failure