Use native Git in CodeBuild to clone, test, then create and push a Git tag when the tests pass
A company uses an AWS CodeCommit repository to store its source code and corresponding unit tests. The company has configured an AWS CodePipeline pipeline that includes an AWS CodeBuild project that runs when code is merged to the main branch of the repository. The company wants the CodeBuild project to run the unit tests. If the unit tests pass, the CodeBuild project must tag the most recent commit. How should the company configure the CodeBuild project to meet these requirements?
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
Option A uses native Git end to end, which is the coherent choice because tagging and pushing a tag are Git operations that Git performs natively (A). Option B mixes the mechanisms: it clones with Git but then tries to create a repository tag using AWS CLI commands, which is not how tags are managed. Options C and D go further and abandon Git entirely, using AWS CLI to copy the code, which loses the working Git metadata needed to create and push a tag in the first place.
Cloning the CodeCommit repository with native Git and running the unit tests, then creating a Git tag and pushing it back to the repository when the tests pass, is exactly what Git is for. Because CodeBuild's native Git mode gives the build a real Git client against the repository, the same tool handles both the checkout and the tag push, and the tag only gets created in the success path of the buildspec so it reflects a commit whose tests passed.
Cloning with native Git but creating the tag with AWS CLI commands (B) — tagging is a Git operation, and driving it through AWS CLI mixes two unrelated mechanisms without a path to push the resulting tag back to CodeCommit. Copying the code with AWS CLI commands and then creating a Git tag (C and D) — once the source is fetched with CLI calls rather than cloned as a Git repository there is no Git working tree or history to tag, so the tagging step cannot be performed as described. Using one mechanism for the whole workflow, as in A, is what makes the sequence work.
Community Discussion (6 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
The requirement is to run unit tests after a merge and, only if they pass, tag the most recent commit. CodeBuild's native Git source mode clones the CodeCommit repository using Git itself, so the build environment contains a real Git working tree with full history. In that state, tagging the current commit and pushing the tag back to CodeCommit are ordinary Git operations, and because both steps are expressed in Git they compose naturally into the buildspec: run the tests, and only on success create the tag and push it (A). Nothing about the workflow requires leaving Git, so the single-mechanism approach is the correct one.Why the Other Options Are Wrong
B configures native Git to clone the repository and run the tests, but then uses AWS CLI commands to create a repository tag. Tags in a Git repository are created and pushed with Git commands; expressing that step through AWS CLI mixes two unrelated mechanisms and does not provide a path to update the repository's refs, so the tag would not be created on the commit as required. C and D go further and configure the project to copy the code from CodeCommit using AWS CLI commands instead of cloning it. Without a Git clone there is no repository working tree, no HEAD pointing at the merged commit, and no history, so creating a Git tag is not possible as described. Using native Git for both the checkout and the tagging, as in A, is what makes the sequence coherent. A is the correct answer.Community Comment Notes
Community voted A unanimously. trungtd explained that configuring CodeBuild to use native Git ensures the repository is cloned in a way that supports all Git operations including tagging and pushing changes, which is the decisive point. syh_rapha cited the CodeCommit documentation for creating a commit and tag. jamesf, tgv, and KaranNishad selected A without further qualification, and no commenter proposed an alternative.Official Reference
Related Analysis
Practice All DOP-C02 Questions
Access 85 questions with complete answers and detailed explanations.
View Full DOP-C02 Practice Test →