Use native Git in CodeBuild to clone, test, then create and push a Git tag when the tests pass

Implement CI/CD pipelines. Integrate automated testing into CI/CD pipelines.
Answer Correct answer: A — clone with native Git, run the unit tests, then create and push a Git tag when they 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?

  1. Configure the CodeBuild project to use native Git to done the CodeCommit repository. Configure the project to run the unit tests. Configure the project to use native Git to create a tag and to push the Git tag to the repository if the code passes the unit tests. Correct Answer
  2. Configure the CodeBuild projed to use native Git to done the CodeCommit repository. Configure the project to run the unit tests. Configure the project to use AWS CLI commands to create a new repository tag in the repository if the code passes the unit tests.
  3. Configure the CodeBuild project to use AWS CLI commands to copy the code from the CodeCommit repository. Configure the project to run the unit tests. Configure the project to use AWS CLI commands to create a new Git tag in the repository if the code passes the unit tests.
  4. Configure the CodeBuild project to use AWS CLI commands to copy the code from the CodeCommit repository. Configure the project to run the unit tests. Configure the project to use AWS CLI commands to create a new repository tag in the repository if the code passes the unit tests.

Community Votes

A
100%

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)

jamesf 👍 2 Selected: A
Option A effectively meets the requirements by using standard Git operations for cloning and tagging, ensuring an efficient and clear workflow for managing the repository in AWS CodePipeline.
tgv 👍 2
---> A
syh_rapha 👍 2 Selected: A
A https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started.html#getting-started-create-commit
trungtd 👍 3 Selected: A
Using Native Git: By configuring CodeBuild to use native Git, you ensure the repository is cloned in a way that supports all Git operations, including tagging and pushing changes. Running Unit Tests: CodeBuild can be set up to run the unit tests using the build specification file (buildspec.yml), ensuring that the tests are executed before any further actions are taken. Creating and Pushing Tags: post_build: commands: - echo Unit tests passed, tagging commit... - git tag -a v1.0.0 -m "Tagging commit after successful unit tests" - git push origin v1.0.0
KaranNishad 👍 2 Selected: A
A is the Answer.
ihustle 👍 2
A is the Answer.

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

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 →

← Back to DOP-C02 Study Guide