Skip to content

AWS.CodeBuild reference

Source: src/AWS/CodeBuild/BatchDeleteBuilds.ts

Runtime binding for codebuild:BatchDeleteBuilds — deletes builds of the bound project by id. Builds that cannot be deleted are returned in buildsNotDeleted with a reason rather than failing the call.

const batchDeleteBuilds = yield* AWS.CodeBuild.BatchDeleteBuilds(project);
const { buildsDeleted, buildsNotDeleted } = yield* batchDeleteBuilds({
ids: oldBuildIds,
});

Source: src/AWS/CodeBuild/BatchGetBuildBatches.ts

Runtime binding for codebuild:BatchGetBuildBatches — reads the status of one or more batch builds of the bound project by batch id.

const batchGetBuildBatches = yield* AWS.CodeBuild.BatchGetBuildBatches(project);
const { buildBatches } = yield* batchGetBuildBatches({ ids: [batchId] });

Source: src/AWS/CodeBuild/BatchGetBuilds.ts

Runtime binding for codebuild:BatchGetBuilds — reads the status of one or more builds by id (the ids returned from StartBuild). Bind it to the project whose builds you poll.

const batchGetBuilds = yield* AWS.CodeBuild.BatchGetBuilds(project);
const { builds } = yield* batchGetBuilds({ ids: [buildId] });
const status = builds?.[0]?.buildStatus; // IN_PROGRESS | SUCCEEDED | FAILED | ...

Source: src/AWS/CodeBuild/BatchGetCommandExecutions.ts

Runtime binding for codebuild:BatchGetCommandExecutions — reads the status and output of sandbox command executions of the bound project.

const batchGetCommandExecutions = yield* AWS.CodeBuild.BatchGetCommandExecutions(project);
const { commandExecutions } = yield* batchGetCommandExecutions({
sandboxId,
commandExecutionIds: [commandId],
});

Source: src/AWS/CodeBuild/BatchGetReports.ts

Runtime binding for codebuild:BatchGetReports — reads one or more reports of the bound report group by report ARN.

const batchGetReports = yield* AWS.CodeBuild.BatchGetReports(reportGroup);
const { reports } = yield* batchGetReports({ reportArns });

Source: src/AWS/CodeBuild/BatchGetSandboxes.ts

Runtime binding for codebuild:BatchGetSandboxes — reads the status of one or more sandboxes of the bound project by sandbox id.

const batchGetSandboxes = yield* AWS.CodeBuild.BatchGetSandboxes(project);
const { sandboxes } = yield* batchGetSandboxes({ ids: [sandboxId] });

Source: src/AWS/CodeBuild/DeleteBuildBatch.ts

Runtime binding for codebuild:DeleteBuildBatch — deletes a batch build of the bound project (and its child builds) by batch id.

const deleteBuildBatch = yield* AWS.CodeBuild.DeleteBuildBatch(project);
yield* deleteBuildBatch({ id: batchId });

Source: src/AWS/CodeBuild/DeleteReport.ts

Runtime binding for codebuild:DeleteReport — deletes a report of the bound report group by report ARN.

const deleteReport = yield* AWS.CodeBuild.DeleteReport(reportGroup);
yield* deleteReport({ arn: reportArn });

Source: src/AWS/CodeBuild/DescribeCodeCoverages.ts

Runtime binding for codebuild:DescribeCodeCoverages — reads the per-file line/branch coverage of a coverage report in the bound report group.

const describeCodeCoverages = yield* AWS.CodeBuild.DescribeCodeCoverages(reportGroup);
const { codeCoverages } = yield* describeCodeCoverages({ reportArn });

Source: src/AWS/CodeBuild/DescribeTestCases.ts

Runtime binding for codebuild:DescribeTestCases — reads the individual test cases of a test report in the bound report group.

const describeTestCases = yield* AWS.CodeBuild.DescribeTestCases(reportGroup);
const { testCases } = yield* describeTestCases({
reportArn,
filter: { status: "FAILED" },
});

Source: src/AWS/CodeBuild/GetReportGroupTrend.ts

Runtime binding for codebuild:GetReportGroupTrend — aggregates a trend statistic (pass rate, duration, …) across the bound report group’s most recent reports.

const getReportGroupTrend = yield* AWS.CodeBuild.GetReportGroupTrend(reportGroup);
const { stats } = yield* getReportGroupTrend({ trendField: "PASS_RATE" });

Source: src/AWS/CodeBuild/InvalidateProjectCache.ts

Runtime binding for codebuild:InvalidateProjectCache — resets the bound project’s build cache so the next build starts cold.

const invalidateProjectCache = yield* AWS.CodeBuild.InvalidateProjectCache(project);
yield* invalidateProjectCache();

Source: src/AWS/CodeBuild/ListBuildBatchesForProject.ts

Runtime binding for codebuild:ListBuildBatchesForProject — lists the bound project’s batch build ids, optionally filtered by status.

const listBuildBatches = yield* AWS.CodeBuild.ListBuildBatchesForProject(project);
const { ids } = yield* listBuildBatches();

Source: src/AWS/CodeBuild/ListBuildsForProject.ts

Runtime binding for codebuild:ListBuildsForProject — lists the bound project’s build ids, newest first. Page with nextToken; resolve ids to statuses with BatchGetBuilds.

const listBuilds = yield* AWS.CodeBuild.ListBuildsForProject(project);
const { ids } = yield* listBuilds();

Source: src/AWS/CodeBuild/ListCommandExecutionsForSandbox.ts

Runtime binding for codebuild:ListCommandExecutionsForSandbox — lists the command executions run in a sandbox of the bound project.

ListCommandExecutionsForSandbox: Sandboxes

Section titled “ListCommandExecutionsForSandbox: Sandboxes”
const listCommandExecutions = yield* AWS.CodeBuild.ListCommandExecutionsForSandbox(project);
const { commandExecutions } = yield* listCommandExecutions({ sandboxId });

Source: src/AWS/CodeBuild/ListReportsForReportGroup.ts

Runtime binding for codebuild:ListReportsForReportGroup — lists the bound report group’s report ARNs, newest first.

ListReportsForReportGroup: Reading Reports

Section titled “ListReportsForReportGroup: Reading Reports”
const listReports = yield* AWS.CodeBuild.ListReportsForReportGroup(reportGroup);
const { reports } = yield* listReports();

Source: src/AWS/CodeBuild/ListSandboxesForProject.ts

Runtime binding for codebuild:ListSandboxesForProject — lists the bound project’s sandbox ids, newest first.

const listSandboxes = yield* AWS.CodeBuild.ListSandboxesForProject(project);
const { ids } = yield* listSandboxes();

Source: src/AWS/CodeBuild/Project.ts

An AWS CodeBuild build project — a reusable definition of how to run a build: the source, the build container, the compute size, the IAM role, and where artifacts land.

The project is a definition only; creating it is instant and free. Running a build (StartBuild) provisions compute and is billed per build-minute.

NO_SOURCE Project with an Inline Buildspec

const project = yield* CodeBuild.Project("Hello", {
serviceRole: role.roleArn,
source: {
type: "NO_SOURCE",
buildspec: [
"version: 0.2",
"phases:",
" build:",
" commands:",
" - echo Hello from CodeBuild",
].join("\n"),
},
environment: {
image: "aws/codebuild/amazonlinux2-x86_64-standard:5.0",
computeType: "BUILD_GENERAL1_SMALL",
},
});

S3-Source Project with S3 Artifacts

const project = yield* CodeBuild.Project("Packager", {
serviceRole: role.roleArn,
source: { type: "S3", location: `${bucket.bucketName}/source.zip` },
artifacts: { type: "S3", location: bucket.bucketName, name: "out.zip", packaging: "ZIP" },
environment: {
image: "aws/codebuild/amazonlinux2-x86_64-standard:5.0",
environmentVariables: [{ name: "STAGE", value: "prod" }],
},
});

Source: src/AWS/CodeBuild/ReportGroup.ts

An AWS CodeBuild report group — a named collection of test or code-coverage reports produced by builds. A build’s buildspec reports: section uploads its test results into a report group, and the report-read bindings (BatchGetReports, DescribeTestCases, …) let runtime code query them.

Test Report Group

const reports = yield* CodeBuild.ReportGroup("UnitTests", {
type: "TEST",
});

Coverage Group Exported to S3

const coverage = yield* CodeBuild.ReportGroup("Coverage", {
type: "CODE_COVERAGE",
exportConfig: {
exportConfigType: "S3",
s3Destination: { bucket: bucket.bucketName, packaging: "ZIP" },
},
});

Source: src/AWS/CodeBuild/RetryBuild.ts

Runtime binding for codebuild:RetryBuild — restarts a finished (failed, stopped, …) build of the bound project by build id, producing a new build.

const retryBuild = yield* AWS.CodeBuild.RetryBuild(project);
const { build } = yield* retryBuild({ id: failedBuildId });

Source: src/AWS/CodeBuild/RetryBuildBatch.ts

Runtime binding for codebuild:RetryBuildBatch — restarts a finished batch build of the bound project, retrying either all builds or only the failed ones (retryType).

const retryBuildBatch = yield* AWS.CodeBuild.RetryBuildBatch(project);
yield* retryBuildBatch({ id: batchId, retryType: "RETRY_FAILED_BUILDS" });

Source: src/AWS/CodeBuild/StartBuild.ts

Runtime binding for codebuild:StartBuild — lets a workload kick off a build of a CodeBuild project (optionally overriding the source version, environment variables, buildspec, etc.).

The response carries the created build including its id, which can be polled with the BatchGetBuilds binding.

const startBuild = yield* AWS.CodeBuild.StartBuild(project);
const { build } = yield* startBuild({
environmentVariablesOverride: [
{ name: "COMMIT", value: sha, type: "PLAINTEXT" },
],
});

Source: src/AWS/CodeBuild/StartBuildBatch.ts

Runtime binding for codebuild:StartBuildBatch — kicks off a batch (fan-out) build of the bound project. The project must have a build batch configuration and the buildspec a batch: section.

const startBuildBatch = yield* AWS.CodeBuild.StartBuildBatch(project);
const { buildBatch } = yield* startBuildBatch();

Source: src/AWS/CodeBuild/StartCommandExecution.ts

Runtime binding for codebuild:StartCommandExecution — runs a shell command in a running sandbox of the bound project. Poll the result with BatchGetCommandExecutions.

const startCommandExecution = yield* AWS.CodeBuild.StartCommandExecution(project);
const { commandExecution } = yield* startCommandExecution({
sandboxId,
command: "echo hello",
});

Source: src/AWS/CodeBuild/StartSandbox.ts

Runtime binding for codebuild:StartSandbox — launches an interactive sandbox environment for the bound project. Run commands in it with StartCommandExecution; stop it with StopSandbox.

const startSandbox = yield* AWS.CodeBuild.StartSandbox(project);
const { sandbox } = yield* startSandbox();

Source: src/AWS/CodeBuild/StopBuild.ts

Runtime binding for codebuild:StopBuild — stops an in-progress build of the bound project by build id.

const stopBuild = yield* AWS.CodeBuild.StopBuild(project);
const { build } = yield* stopBuild({ id: buildId });
// build.buildStatus transitions to "STOPPED"

Source: src/AWS/CodeBuild/StopBuildBatch.ts

Runtime binding for codebuild:StopBuildBatch — stops an in-progress batch build of the bound project by batch id.

const stopBuildBatch = yield* AWS.CodeBuild.StopBuildBatch(project);
yield* stopBuildBatch({ id: batchId });

Source: src/AWS/CodeBuild/StopSandbox.ts

Runtime binding for codebuild:StopSandbox — stops a running sandbox of the bound project by sandbox id.

const stopSandbox = yield* AWS.CodeBuild.StopSandbox(project);
yield* stopSandbox({ id: sandboxId });