Batch builds in Amazon CodeBuild - Amazon CodeBuild
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Batch builds in Amazon CodeBuild

You can use Amazon CodeBuild to run concurrent and coordinated builds of a project with batch builds.

Security role

Batch builds introduce a new security role in the batch configuration. This new role is required as CodeBuild must be able to call the StartBuild, StopBuild, and RetryBuild actions on your behalf to run builds as part of a batch. Customers should use a new role, and not the same role they use in their build, for two reasons:

  • Giving the build role StartBuild, StopBuild, and RetryBuild permissions would allow a single build to start more builds via the buildspec.

  • CodeBuild batch builds provide restrictions that restrict the number of builds and compute types that can be used for the builds in the batch. If the build role has these permissions, it is possible the builds themselves could bypass these restrictions.

Batch build types

CodeBuild supports the following batch build types:

Build graph

A build graph defines a set of tasks that have dependencies on other tasks in the batch.

The following example defines a build graph that creates a dependency chain.

batch: fast-fail: false build-graph: - identifier: build1 env: variables: BUILD_ID: build1 ignore-failure: false - identifier: build2 buildspec: build2.yml env: variables: BUILD_ID: build2 depend-on: - build1 - identifier: build3 env: variables: BUILD_ID: build3 depend-on: - build2

In this example:

  • build1 runs first because it has no dependencies.

  • build2 has a dependency on build1, so build2 runs after build1 completes.

  • build3 has a dependency on build2, so build3 runs after build2 completes.

For more information about the build graph buildspec syntax, see batch/build-graph.

Build list

A build list defines a number of tasks that run in parallel.

The following example defines a build list. The build1 and build2 builds will run in parallel.

batch: fast-fail: false build-list: - identifier: build1 env: variables: BUILD_ID: build1 ignore-failure: false - identifier: build2 buildspec: build2.yml env: variables: BUILD_ID: build2 ignore-failure: true

For more information about the build list buildspec syntax, see batch/build-list.

Build matrix

A build matrix defines tasks with different configurations that run in parallel. CodeBuild creates a separate build for each possible configuration combination.

The following example shows a build matrix with two buildspec files and three values for an environment variable.

batch: build-matrix: static: ignore-failure: false dynamic: buildspec: - matrix1.yml - matrix2.yml env: variables: MY_VAR: - VALUE1 - VALUE2 - VALUE3

In this example, CodeBuild creates six builds:

  • matrix1.yml with $MY_VAR=VALUE1

  • matrix1.yml with $MY_VAR=VALUE2

  • matrix1.yml with $MY_VAR=VALUE3

  • matrix2.yml with $MY_VAR=VALUE1

  • matrix2.yml with $MY_VAR=VALUE2

  • matrix2.yml with $MY_VAR=VALUE3

Each build will have the following settings:

  • ignore-failure set to false

  • env/type set to LINUX_CONTAINER

  • env/image set to aws/codebuild/amazonlinux2-x86_64-standard:4.0

  • env/privileged-mode set to true

These builds run in parallel.

For more information about the build matrix buildspec syntax, see batch/build-matrix.

Batch report mode

If the source provider for your project is Bitbucket, GitHub, or GitHub Enterprise, and your project is configured to report build statuses to the source provider, you can select how you want your batch build statuses sent to the source provider. You can select to have the statuses sent as a single aggregate status report for the batch, or have the status of each build in the batch reported individually.

For more information, see the following topics:

More information

For more information, see the following topics: