You can create an npm script, as shown below, to abandon the build if tests fail:
 "scripts" : { "cibuild": "ng test --code-coverage && ng build --prod --no-progress" } 
The above assumes that you have singleRun: true in the karma.conf.js file. Then you can run npm run cibuild , which will run the tests first, and then build only if the tests pass. We use this for our CI assembly through Jenkins and then scanning the sonar.
 source share