Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run ng test before ng build --prod and fail jenkins job when ng test fails?

Earlier I used systemJS version of angular-cli and whenever I used to kick a build from jenkins, the build used to fail if there were any test case failure.

I just had ng build --prod command to build my project.

Now with webpack version of angular-cli, we have to explicitly run ng test.

How can I check in jenkins whether ng test have succeeded and continue with ng build --prod or else fail the build?

like image 654
Gan Avatar asked Nov 01 '16 18:11

Gan


People also ask

Does NG test also build?

The ng test command builds the application in watch mode, and launches the Karma test runner.

How do you run ng build in Jenkins?

In Jenkins, go to the project configuration of the project for which you want to run an automated build. In the 'Build Triggers' section, select 'Build when a change is pushed to GitHub'. Save your project.


1 Answers

You can create a npm script like below to fail your build in case the tests fail:

"scripts" : {
    "cibuild": "ng test --code-coverage && ng build --prod --no-progress"
 }

The above is assuming you have singleRun: true in your karma.conf.js file. Then you can run npm run cibuild which will first run tests and then build only if tests pass. We use this for our CI build through Jenkins followed by a Sonar scan.

like image 166
ashish.gd Avatar answered Sep 24 '22 00:09

ashish.gd