A development team uses AWS CodeBuild to compile a Node.js service and run its unit tests. The team wants the dependency install to happen first, the unit tests to run only after a successful install, and the compiled output to be packaged for the next pipeline stage. In which sequence of buildspec phases should the team place these commands so CodeBuild runs them in the intended order?
- APut the dependency install in the build phase, run the unit tests in the install phase, and package the output in the pre_build phase of the buildspec file.
- BPut the dependency install in the install phase, run the unit tests in the build phase, and package the compiled output in the post_build phase of the buildspec file. Correct
- CPut the dependency install in the post_build phase, run the unit tests in the pre_build phase, and package the compiled output in the install phase of the buildspec file.
- DPut all three commands in a single pre_build phase and rely on CodeBuild to reorder them by dependency so install, tests, and packaging each run correctly.
Why A is wrong: This inverts the phase order, because install runs before pre_build and build, so placing tests in install would run them before dependencies are even fetched.
Why B is correct: CodeBuild executes install, then pre_build, then build, then post_build in that fixed order, so this mapping runs the steps exactly as the team intends.
Why C is wrong: This is tempting if phase names are read loosely, but post_build runs last, so installing dependencies there would happen after tests had already failed.
Why D is wrong: CodeBuild runs commands in the literal order written and does not reorder them by dependency, so collapsing every step into one phase gives no guaranteed sequencing.