Gan
Gan

Reputation: 945

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?

Upvotes: 12

Views: 6861

Answers (1)

ashish.gd
ashish.gd

Reputation: 1768

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.

Upvotes: 9

Related Questions