AWS CodeBuild integration
  • 08 Sep 2022
  • 3 Minutes to read
  • Contributors
  • Dark
    Light

AWS CodeBuild integration

  • Dark
    Light

Autify provides an official way to integrate with AWS CodeBuild to run a test plan or test scenario easily from your CodeBuild project.

Getting started

This document describes how to use our AWS CodeBuild integrations with your CodeBuild project step-by-step.

Prerequisites

First, we assume you already have a CodeBuild project to deploy your software to somewhere e.g. staging, production. We'll add an Autify test commands right after the deployment command to confirm the newly deployed software doesn't break the end-to-end experience.

Secondly, you need to create a test plan or test scenario on Autify for Web. The test scenario should be recorded against your target website where the software is deployed by your CodeBuild project. Please note the URL of your test plan or scenario e.g. https://app.autify.com/projects/00/scenarios/000 and we'll use it later.

You also need to create a personal access token for Autify for Web. Please note the generated token somewhere so that we can store the value on AWS Systems Manager Parameter Store or AWS Secrets Manager later.

Note: Since the personal access token is associated with a single user, we recommend you to create a machine user in your organization and use its personal access token for CI/CD integration.

Store personal access token on AWS Systems Manager Parameter Store or AWS Secrets Manager

Store the personal access token you generated above on AWS Systems Manager Parameter Store or AWS Secrets Manager in the same AWS region.

For Parameter Store, you can create a new parameter via CodeBuild console, Parameter Store console, etc. The parameter name is arbitrary but we assume you name it /CodeBuild/AUTIFY_WEB_ACCESS_TOKEN. Use SecureString type to keep it secure. See AWS's walkthrough as a reference.

For Secrets Manager, you can create a new secret via Secrets Manager console, etc. The secret name is arbitrary but we assume you name it /CodeBuild/AUTIFY_WEB_ACCESS_TOKEN with Plaintext type. See AWS's walkthrough as a reference.

Do not store this value in buildspec.yml directly since it will be visible as plain text.

Add CodeBuild commands to run Autify for Web

Finally, let's add a new commands to your existing CodeBuild project or a new project. Open your buildspec.yml in your repository or CodeBuild console and edit by refering the examples below. The URL value (https://app.autify.com/projects/00/scenarios/000) should be the URL you noted above.

We assume you use Linux environment image. aws/codebuild/amazonlinux2-aarch64-* would be the best because it's the cheapest.

You can also configure the environment variable in the console "Edit" > "Environment" > "Additional configuration" or UpdateProject API.


Simply start a test and finish the step (no waiting for the finish of the test):

phases:
  install:
    commands:
      - curl https://autify-cli-assets.s3.amazonaws.com/autify-cli/channels/stable/install-standalone.sh | sh
  build:
    commands:
      - autify web test run https://app.autify.com/projects/00/scenarios/000
env:
  parameter-store:
    AUTIFY_WEB_ACCESS_TOKEN: "/CodeBuild/AUTIFY_WEB_ACCESS_TOKEN"
  # OR
  secrets-manager:
    AUTIFY_WEB_ACCESS_TOKEN: "/CodeBuild/AUTIFY_WEB_ACCESS_TOKEN"

Start a test and wait until the test finishes or timed out:

phases:
  install:
    commands:
      - curl https://autify-cli-assets.s3.amazonaws.com/autify-cli/channels/stable/install-standalone.sh | sh
  build:
    commands:
      - autify web test run https://app.autify.com/projects/00/scenarios/000 --wait --timeout 300
env:
  parameter-store:
    AUTIFY_WEB_ACCESS_TOKEN: "/CodeBuild/AUTIFY_WEB_ACCESS_TOKEN"
  # OR
  secrets-manager:
    AUTIFY_WEB_ACCESS_TOKEN: "/CodeBuild/AUTIFY_WEB_ACCESS_TOKEN"

CAVEAT: This will consume your CodeBuild build minutes while waiting. Be careful when extending the timeout value.

Use --url-replacements to start your test plan or scenario against a different URL:

phases:
  install:
    commands:
      - curl https://autify-cli-assets.s3.amazonaws.com/autify-cli/channels/stable/install-standalone.sh | sh
  build:
    commands:
      - autify web test run https://app.autify.com/projects/00/scenarios/000 --url-replacements http://example.com=http://example.net
env:
  parameter-store:
    AUTIFY_WEB_ACCESS_TOKEN: "/CodeBuild/AUTIFY_WEB_ACCESS_TOKEN"
  # OR
  secrets-manager:
    AUTIFY_WEB_ACCESS_TOKEN: "/CodeBuild/AUTIFY_WEB_ACCESS_TOKEN"

--url-replacements is useful when you want to test your staging website using a test scenaio recorded against your production website, for example.

Conclusion

By using Autify's AWS CodeBuild integration, you can automatically run a test plan or scenario after deployments so that you can detect regressions right away and take appropriate actions without wasting time.


First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.