Immutable solution version
CodeBuild keeps going after a failed command and still uploads artifacts
Complete solution
CodeBuild keeps going after a failed command and still uploads artifacts: Two things to fix.
Two things to fix. First, make sure every failing command actually exits nonzero; a test runner that swallows failures or a command chain joined with semicolons will report success and CodeBuild will happily continue. Use set -e or && chains in your buildspec commands. Second, know that postbuild runs even after a failed build phase by design, for debug artifacts. If you need different postbuild behavior on failure, branch on the built-in CODEBUILDBUILDSUCCEEDING env var, which is 1 when the build phase succeeded and 0 when it did not.
Context: Stack Overflow #46584324 (accepted answer, 46 votes): a build fails on a test syntax error, yet CodeBuild moves on to the next phase and even produces artifacts. The asker expected execution to stop. The accepted answer explains the two mechanics behind this: CodeBuild detects failure purely by exit codes, and the post_build phase always runs whenever the build phase ran, so you can collect debug output.
Matched source
Source: Published skill Original query: "CodeBuild keeps going after a failed command and still uploads artifacts" Key terms: after, artifacts, codebuild, command, failed, going, keeps, still, uploads
Evidence
Source: Stack Overflow #46584324 (accepted answer, 46 votes): a build fails on a test syntax error, yet CodeBuild moves on to the next phase and even produces artifacts. The asker expected execution to stop. The accepted answer explains the two mechanics behind this: CodeBuild detects failure purely by exit codes, and the post_build phase always runs whenever the build phase ran, so you can collect debug output.
Verified resolution: Two things to fix. First, make sure every failing command actually exits nonzero; a test runner that swallows failures or a command chain joined with semicolons will report success and CodeBuild will happily continue. Use set -e or && chains in your buildspec commands. Second, know that postbuild runs even after a failed build phase by design, for debug artifacts. If you need different postbuild behavior on failure, branch on the built-in CODEBUILDBUILDSUCCEEDING env var, which is 1 when the build phase succeeded and 0 when it did not.
Source URL: https://stackoverflow.com/questions/46584324/codebuild-execution-continues-after-build-fails-instead-of-stopping
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_LHPnJSRu3RoosHd1LA32gQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">CodeBuild keeps going after a failed command and still uploads artifacts <span>— Vectle</span></a>