build - CodeBuild 执行在构建失败后继续执行,而不是停止

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

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

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

请参阅下面的构建规范。

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

POST_BUILD will always run as long as BUILD was also run (不管BUILD 的成功或失败。)UPLOAD_ARTIFACTS 也是如此。这样您就可以检索调试信息/工件。

如果你想在POST_BUILD中根据BUILD的成败做一些不同的事情,可以测试builtin environment variable CODEBUILD_BUILD_SUCCEEDING ,如果 BUILD 成功则设置为 1,如果失败则设置为 0

https://stackoverflow.com/questions/46584324/

相关文章:

c# - 是否有 Visual Studio 构建探查器?

qt - Qt的配置有哪些不同的平台

build - 在构建服务器上使用 ramdisk 是否明智?

android - 如何加快 android ndk 构建

parameters - TeamCity 条件参数值

c# - 错误构建 VSTS : ## [error] Error: Unable to locat

Maven - 从外部属性文件中读取属性

scala - 如何为 SBT 设置默认项目

ios - 带有 "Release: Fastest, Smallest [-Os]"的 Xcode

java - 如果未激活另一个配置文件,则激活 Maven 配置文件