An AWS CodeBuild project is the build stage of an AWS CodePipeline pipeline.
Its buildspec installs dependencies and runs npm run build, which writes the site to a folder named dist. The build succeeds, but the deploy stage that follows reports that it received no input artifact. The buildspec has no artifacts section.
What should the developer change?
Choose one answer.
AA. Move npm run build from the build phase into the post_build phase, so the output is written after the build phase ends.
BB. Add a cache section to the buildspec that lists the dist folder, so the output is saved between builds.
CC. Add an artifacts section with files set to '**/*' and base-directory set to dist.
DD. Set the project's artifact type to NO_ARTIFACTS in the pipeline's build action, so that CodeBuild uploads the output.
Show the answer and explanation
Answer: C
A. Wrong: Phase names control the order of commands inside CodeBuild, but they do not decide what is passed on as output. The dist folder would still not be declared as an artifact, so the deploy stage would still receive nothing.
B. Wrong: The cache section saves files such as dependencies between builds to speed them up. It does not pass build output to the next pipeline stage.
D. Wrong: NO_ARTIFACTS tells CodeBuild that the project produces no output, which is the opposite of what the pipeline needs. The buildspec still needs an artifacts section that names the files.
Explanation
A CodePipeline build stage passes on only what the buildspec declares in its artifacts section. files selects the build output, and base-directory sets the top-level folder whose contents are packaged, so dist's contents are not wrapped in a dist folder. Without an artifacts section, the next stage has nothing to deploy.
Want more on CI/CD with CodePipeline and CodeBuild? The 5 full-length practice sets have 18 more CI/CD with CodePipeline and CodeBuild questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets →