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?
The ng test command builds the application in watch mode, and launches the Karma test runner.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With