Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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

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

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

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

1 Answer

0 votes
by (44.4k points)

CodeBuild detects build failures by exit codes. You should ensure that your test execution returns 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.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories

...