[英]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. 较早之前,我使用了angularJS的systemJS版本,每当我使用jenkins进行构建时,如果有任何测试用例失败,该构建就会失败。
I just had ng build --prod
command to build my project. 我刚刚有ng build --prod
命令来构建我的项目。
Now with webpack version of angular-cli, we have to explicitly run ng test
. 现在使用angular-cli的webpack版本,我们必须显式运行ng test
。
How can I check in jenkins whether ng test
have succeeded and continue with ng build --prod
or else fail the build? 我该如何在jenkins中检查ng test
是否成功,并继续进行ng build --prod
还是构建失败?
You can create a npm script like below to fail your build in case the tests fail: 您可以创建如下所示的npm脚本,以防测试失败而导致构建失败:
"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. 以上假设您的karma.conf.js文件中具有singleRun: true
。 Then you can run npm run cibuild
which will first run tests and then build only if tests pass. 然后,您可以运行npm run cibuild
,它将首先运行测试,然后仅在测试通过时才进行构建。 We use this for our CI build through Jenkins followed by a Sonar scan. 我们通过Jenkins将其用于CI构建,然后进行声纳扫描。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.