构建失败后代码构建继续(Code build continues after build fails)

我正在使用git,codebuild和elastic beanstalk构建CI / CD管道。

在代码构建执行期间,当构建由于测试用例的语法错误而失败时,我看到代码构建进展到下一阶段并最终继续产生工件。

我的理解是如果构建失败,执行应该停止。 这是正确的行为吗?

请参阅下面的buildspec。

version: 0.2 phases: install: commands: - echo Installing package.json.. - npm install - echo Installing Mocha... - npm install -g mocha pre_build: commands: - echo Installing source NPM placeholder dependencies... build: commands: - echo Build started on `date` - echo Compiling the Node.js code - mocha modules/**/tests/*.js post_build: commands: - echo Build completed on `date` artifacts: files: - modules/* - node_modules/* - package.json - config/* - server.js

I'm building a CI/CD pipeline using git, codebuild and elastic beanstalk.

During codebuild execution when build fails due to syntax error of a test case, I see codebuild progress to next stage and ultimatly go on to produce the artifacts.

My understanding was if the build fails, execution should stop. is this a correct behavior ?

Please see the buildspec below.

version: 0.2 phases: install: commands: - echo Installing package.json.. - npm install - echo Installing Mocha... - npm install -g mocha pre_build: commands: - echo Installing source NPM placeholder dependencies... build: commands: - echo Build started on `date` - echo Compiling the Node.js code - mocha modules/**/tests/*.js post_build: commands: - echo Build completed on `date` artifacts: files: - modules/* - node_modules/* - package.json - config/* - server.js

最满意答案

CodeBuild通过退出代码检测构建失败。 您应确保测试执行失败时返回非零退出代码。

只要BUILD也运行, POST_BUILD将始终运行 (无论BUILD的成功或失败。) UPLOAD_ARTIFACTS 。 这样您就可以检索调试信息/工件。

如果您想在POST_BUILD执行不同的POST_BUILD具体取决于BUILD的成功或失败,您可以测试内置环境变量CODEBUILD_BUILD_SUCCEEDING ,如果BUILD成功则设置为1 ,如果失败则设置为0 。

CodeBuild detects build failures by exit codes. You should ensure that your test execution returns a non-zero exit code on failure.

POST_BUILD will always run as long as BUILD was also run (regardless of BUILD's success or failure.) The same goes for UPLOAD_ARTIFACTS. This is so you can retrieve debug information/artifacts.

If you want to do something different in POST_BUILD depending on the success or failure of BUILD, you can test the builtin environment variable CODEBUILD_BUILD_SUCCEEDING, which is set to 1 if BUILD succeeded, and 0 if it failed.

更多推荐

构建,echo,codebuild,commands,电脑培训,计算机培训,IT培训"/> <meta name="de