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,请将configuration对象的BatchEnabled参数设置为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 文件中指定的输出构件的名称必须与构建规范文件中定义的构建和构件的标识符相匹配。主要工件的语法是 buildIdentif ier,次要工件的语法是 buildIdentif ier _ ArtifactI dentifier。

例如,对于输出对象名称build1, CodeBuild 会将的主要构件上传build1到的位置build1。对于输出名称build1_artifact1, CodeBuild 会将artifact1的辅助对象上传build1到的位置build1_artifact1,依此类推。如果仅指定了一个输出位置,则名称应仅为 BuildIdentif ier。

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

使用组合构件进行Batch 构建

使用以下 JSON 文件作为流水线结构的示例,该管道结构使用组合构件创建批量构建。要启用批量构建 CodePipeline,请将configuration对象的BatchEnabled参数设置为true。要将构建工件合并到同一位置,请将configuration对象的CombineArtifacts参数设置为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 参数。有关更多信息,请参阅Amazon CodePipeline用户指南中的创建管道 (CLI)