AWS CodePipeline與 的整合 CodeBuild 和批次組建 - AWS CodeBuild

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS CodePipeline與 的整合 CodeBuild 和批次組建

AWS CodeBuild現在支援批次建置。本範例將示範如何使用AWS CodePipeline來建立使用批量建置的建置專案。

您可以使用 JSON 格式檔案來定義管道的結構,再透過 AWS CLI 使用此檔案來建立管道。如需詳細資訊,請參閱「」AWS CodePipeline管道結構參考中的AWS 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 檔案中定義的建置和成品的標識符。語法是建築識別人對於主對象,建築識別人_ArtideIdentifier用於輔助工件。

例如,對於輸出工件名稱build1、 CodeBuild 將上載build1設置到build1。如需輸出名稱build1_artifact1、 CodeBuild 將上傳輔助對象artifact1build1設置到build1_artifact1,以此類推。如果只指定了一個輸出位置,則該名稱應為建築識別人僅 。

建立 JSON 檔案之後,您可以建立管道。使用 AWS CLI 來執行 create-pipeline 命令,並將檔案傳給 --cli-input-json 參數。如需詳細資訊,請參閱「」建立管道 (CLI)中的AWS 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 檔案之後,您可以建立管道。使用 AWS CLI 來執行 create-pipeline 命令,並將檔案傳給 --cli-input-json 參數。如需詳細資訊,請參閱「」建立管道 (CLI)中的AWS CodePipeline使用者指南