【发布时间】:2022-10-06 05:31:55
【问题描述】:
我正在使用带有(codeCommit、codebuild、codeDeploy)的代码管道做一个非常简单的 CI/CD。
我有一个简单的 node.js 应用程序,它有一个如下所示的单元测试
const Allsayings = require(\'./testAllsayings\');
function logPass(tName){
console.log(\"PASS - \" + tName);
}
function logFail(tName){
console.log(\"FAIL - \" + tName )
}
// T01 - Search for a saying and succeed
let say01 = new Allsayings();
say01.addQuote(\"Everyone is looking for something.\");
say01.addQuote(\"Let\'s try to figure this out together, so help me please\");
let output01 = aq01.findSaying(\"Not here\");
if (output01.search(\"Before you embark\") > -1){
logPass(\"T01\");
} else {
logFail(\"T01\");
}
我希望当单元测试失败时它会停止/停止部署或管道的进展。
我的 byuildspec
version: 0.2
phases:
install:
runtime-versions:
nodejs: 16
commands:
- echo Installing
pre_build:
commands:
- echo Installing source NPM dependencies.
- cd serverSide
- npm install
build:
commands:
- echo Build started on `date`
- npm install pm2@latest -g
# buildspec is able to get into your servSide file?
- ls
- echo \"for debugging ... starting test\"
- node testAllsayings.js
- echo \"test is successful ... \"
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- \'**/*\'
但是,我的问题是,当我运行 codepipeline 时,尽管我的 unittest 失败了,但 codebuild 仍成功完成,这是 codebuild 日志的一部分
[Container] 2022/10/03 00:45:05 Running command echo \"for debugging ... starting test\"
for debugging ... starting test
[Container] 2022/10/03 00:45:05 Running command node testAllsayings.js
Fail - T01
[Container] 2022/10/03 00:45:05 Running command echo \"test is successful ... \"
test is successful ...
我阅读了this,并将命令node testAllsayings.js 移动到了pre_build 阶段,但在没有停止构建阶段或部署阶段的情况下一切正常。
标签: node.js amazon-web-services aws-codepipeline aws-codebuild aws-code-deploy