Skip to Content

Amazon DOP-C02: AWS CodeBuild Configuring Unit Tests and Tagging in CodeCommit

Learn how to set up an AWS CodeBuild project to run unit tests on code in a CodeCommit repository and tag the latest commit if tests pass. Best practices for integrating testing into your CI/CD pipeline.

Table of Contents

Question

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?

A. 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.
B. 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.
C. 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.
D. 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.

Answer

A. 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.

Explanation

To meet the requirements, the CodeBuild project needs to:

  1. Clone the code from the CodeCommit repository
  2. Run the unit tests on the code
  3. If the tests pass, tag the most recent commit in the repository

Using native Git commands in the CodeBuild project is the best way to accomplish this:

  1. Cloning the repo with Git ensures CodeBuild gets the full commit history and can work with tags. The AWS CLI copy command would only get the code files.
  2. After cloning, the CodeBuild project can run the unit tests based on its configuration.
  3. If the tests pass, the project should use the `git tag` command to create a new tag pointing to the most recent commit. It then needs to push that tag to the CodeCommit repository using `git push origin <tag-name>`.

The other options have a few issues:

  • B and D suggest creating an AWS “repository tag” which is not the same as a Git tag. CodeCommit repository tags don’t mark specific commits.
  • C and D suggest using the AWS CLI to copy the code, which wouldn’t bring over the Git metadata and commit history needed for creating Git tags.

So in summary, option A provides the correct set of steps using native Git capabilities to clone the code, run tests, tag the latest commit, and push the tag to the repository. This allows CodeBuild to effectively integrate testing and tagging into the CI/CD pipeline.

Amazon AWS Certified DevOps Engineer – Professional DOP-C02 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Amazon AWS Certified DevOps Engineer – Professional DOP-C02 exam and earn Amazon AWS Certified DevOps Engineer – Professional DOP-C02 certification.