Amazon CodePipeline与 集成 CodeBuild 批量构建 - Amazon CodeBuild
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon CodePipeline与 集成 CodeBuild 批量构建

Amazon CodeBuild现在支持批处理生成。此示例演示如何使用Amazon CodePipeline创建使用批量构建构建构建构建构建构建构建

您可以使用定义管道结构的 JSON 格式文件,然后将其与 Amazon CLI 配合使用来创建管道。有关更多信息,请参阅 。Amazon CodePipeline管道结构参考中的Amazon CodePipeline用户指南.

使用单个工件 Batch 构建

使用以下 JSON 文件作为管道结构的示例,此管道结构创建一个具有单独构件的批处理构建。要在 CodePipeline 中启用批量构建,请将BatchEnabled的参数configuration反对true.

{ "pipeline": { "roleArn": "arn:aws:iam::account-id:role/my-AWS-CodePipeline-service-role-name", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source1", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source1" } ], "configuration": { "S3Bucket": "my-input-bucket-name", "S3ObjectKey": "my-source-code-file-name.zip" }, "runOrder": 1 }, { "inputArtifacts": [], "name": "Source2", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source2" } ], "configuration": { "S3Bucket": "my-other-input-bucket-name", "S3ObjectKey": "my-other-source-code-file-name.zip" }, "runOrder": 1 } ] }, { "name": "Build", "actions": [ { "inputArtifacts": [ { "name": "source1" }, { "name": "source2" } ], "name": "Build", "actionTypeId": { "category": "Build", "owner": "AWS", "version": "1", "provider": "AWS CodeBuild" }, "outputArtifacts": [ { "name": "build1" }, { "name": "build1_artifact1" }, { "name": "build1_artifact2" }, { "name": "build2_artifact1" }, { "name": "build2_artifact2" } ], "configuration": { "ProjectName": "my-build-project-name", "PrimarySource": "source1", "BatchEnabled": "true" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "AWS-CodePipeline-internal-bucket-name" }, "name": "my-pipeline-name", "version": 1 } }

以下是一个示例 CodeBuild buildspec 文件将与此管道配置一起使用。

version: 0.2 batch: build-list: - identifier: build1 env: compute-type: BUILD_GENERAL1_SMALL - identifier: build2 env: compute-type: BUILD_GENERAL1_MEDIUM phases: build: commands: - echo 'file' > output_file artifacts: files: - output_file secondary-artifacts: artifact1: files: - output_file artifact2: files: - output_file

管道的 JSON 文件中指定的输出构件的名称必须与 buildspec 文件中定义的构建和构件的标识符相匹配。语法如下:构建标识符对于主要工件,以及构建标识符_ArtifactIdentifier对于次要工件。

例如,对于输出工件名称build1、 CodeBuild 将上传的主要工件build1到的位置build1. 对于输出名称build1_artifact1、 CodeBuild 将上传辅助工件artifact1build1到的位置build1_artifact1、、、等等。如果只指定了一个输出位置,则名称应为构建标识符仅限 。

创建 JSON 文件后,可以创建管道。使用 Amazon CLI 运行 create-pipeline 命令并将此文件传递给 --cli-input-json 参数。有关更多信息,请参阅 。创建管道 (CLI)中的Amazon CodePipeline用户指南.

使用组合工件 Batch 构建

使用以下 JSON 文件作为管道结构的示例,此管道结构创建一个具有组合项目的批处理构建。要在 CodePipeline 中启用批量构建,请将BatchEnabled的参数configuration反对true. 要将构建工件组合到同一位置,请将CombineArtifacts的参数configuration反对true.

{ "pipeline": { "roleArn": "arn:aws:iam::account-id:role/my-AWS-CodePipeline-service-role-name", "stages": [ { "name": "Source", "actions": [ { "inputArtifacts": [], "name": "Source1", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source1" } ], "configuration": { "S3Bucket": "my-input-bucket-name", "S3ObjectKey": "my-source-code-file-name.zip" }, "runOrder": 1 }, { "inputArtifacts": [], "name": "Source2", "actionTypeId": { "category": "Source", "owner": "AWS", "version": "1", "provider": "S3" }, "outputArtifacts": [ { "name": "source2" } ], "configuration": { "S3Bucket": "my-other-input-bucket-name", "S3ObjectKey": "my-other-source-code-file-name.zip" }, "runOrder": 1 } ] }, { "name": "Build", "actions": [ { "inputArtifacts": [ { "name": "source1" }, { "name": "source2" } ], "name": "Build", "actionTypeId": { "category": "Build", "owner": "AWS", "version": "1", "provider": "AWS CodeBuild" }, "outputArtifacts": [ { "name": "output1 " } ], "configuration": { "ProjectName": "my-build-project-name", "PrimarySource": "source1", "BatchEnabled": "true", "CombineArtifacts": "true" }, "runOrder": 1 } ] } ], "artifactStore": { "type": "S3", "location": "AWS-CodePipeline-internal-bucket-name" }, "name": "my-pipeline-name", "version": 1 } }

以下是一个示例 CodeBuild buildspec 文件将与此管道配置一起使用。

version: 0.2 batch: build-list: - identifier: build1 env: compute-type: BUILD_GENERAL1_SMALL - identifier: build2 env: compute-type: BUILD_GENERAL1_MEDIUM phases: build: commands: - echo 'file' > output_file artifacts: files: - output_file

如果为批量构建启用了组合对象,则只允许一个输出。 CodeBuild 将把所有内部版本的主要工件合并到一个 ZIP 文件中。

创建 JSON 文件后,可以创建管道。使用 Amazon CLI 运行 create-pipeline 命令并将此文件传递给 --cli-input-json 参数。有关更多信息,请参阅 。创建管道 (CLI)中的Amazon CodePipeline用户指南.