CodeBuild 执行在构建失败后继续执行,而不是停止 [英] CodeBuild execution continues after build fails instead of stopping

查看:10
本文介绍了CodeBuild 执行在构建失败后继续执行,而不是停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 ultimately 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 通过退出代码检测构建失败.您应该确保您的测试执行在失败时返回非零退出代码.

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

BUILD 也运行过,>POST_BUILD 就会一直运行(不管 BUILD 是成功还是失败.)对于 BUILD 也是如此.代码>UPLOAD_ARTIFACTS.这样您就可以检索调试信息/工件.

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.

如果你想在POST_BUILD中根据BUILD的成败做一些不同的事情,你可以测试内置环境变量CODEBUILD_BUILD_SUCCEEDING,设置为1 如果 BUILD 成功,0 如果失败.

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.

这篇关于CodeBuild 执行在构建失败后继续执行,而不是停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆