AWS CodeBuild identifies build as success in spite of test cases failing

2.3k Views Asked by At

I am new to AWS CodeBuild. I am trying to run some cucumber-js test cases using CodeBuild. After the execution of tests, I get the results of the test cases printed out in the console and logs (CloudWatch).

What I am observing is that irrespective of the test results, the buildStatus always shows as succeeded and in the logs, it says 'Phase complete: BUILD Success: true'. This is not desired since I need the build phase to fail.

Here is part of the log file output:

46 scenarios (4 failed, 42 passed) 317 steps (4 failed, 4 skipped, 309 passed) 0m24.718s going to kill process tests completed

[Container] Phase complete: BUILD Success: true

As you can see, the build says success: true in spite of the fact that some of the tests failed.

I am not using a buildspec.yml since that is optional. I use a shell script to do the tests like so:

node ./node_modules/.bin/cucumber-js --format-options '{"colorsEnabled":false}'

Any help would be appreciated.. Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

I was using a shell script instead of buildspec.yml and was not passing the return code of the node command back to CodeBuild from the script. So there was no way for CodeBuild to understand if there was any failure. When I captured the exit code and returned it from the script, it started identifying the test failures.

node ./node_modules/.bin/cucumber-js --format-options '{"colorsEnabled":false}

exitcode=$?; exit $exitcode;

Thanks to the comment made by awsnitin, I could resolve the issue.