翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
このセクションでは、CodePipeline と CodeBuild 間のサンプル統合について説明します。
サンプル | 説明 |
---|---|
これらのサンプルでは、AWS CodePipeline を使用して、バッチビルドを使用するビルドプロジェクトを作成する方法を示します。 |
|
このサンプルでは、複数の入力ソースを使用して複数の出力アーティファクトを作成するビルドプロジェクトを AWS CodePipeline で作成する方法を示します。 |
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": "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 ファイルで定義されているビルドおよびアーティファクトの識別子と一致していなければなりません。構文は、プライマリアーティファクトの場合は buildIdentifier
で、セカンダリアーティファクトの場合は buildIdentifier
_artifactIdentifier
です。
たとえば、出力アーティファクト名 build1
の場合、CodeBuild は build1
の場所に「build1
」を出力します。出力名は「build1_artifact1
」であり、CodeBuild はセカンダリアーティファクトを artifact1
の build1
、build1_artifact1
の場所にアップロードします。出力場所が 1 つだけ指定されている場合、名前は buildIdentifier
のみにします。
JSON ファイルを作成したら、パイプラインを作成することができます。AWS CLI を使用して create-pipeline コマンドを実行し、ファイルを --cli-input-json
パラメータに渡します。詳細については、『AWS CodePipeline ユーザーガイド』の「パイプラインの作成 (CLI)」を参照してください。
複合アーチファクトを使用した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": "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
結合アーチファクトがバッチ構築で有効になっている場合、出力は 1 つだけです。CodeBuild は、すべてのビルドの主要なアーティファクトを 1 つのZIPファイルに結合します。
JSON ファイルを作成したら、パイプラインを作成することができます。AWS CLI を使用して create-pipeline コマンドを実行し、ファイルを --cli-input-json
パラメータに渡します。詳細については、『AWS CodePipeline ユーザーガイド』の「パイプラインの作成 (CLI)」を参照してください。
複数の入力ソースおよび出力アーティファクトを持つ CodePipeline/CodeBuild の統合のサンプル
AWS CodeBuild プロジェクトは、複数の入力ソースを使用できます。また、複数の出力アーティファクトを作成することもできます。このサンプルでは、複数の入力ソースを使用して複数の出力アーティファクトを作成するビルドプロジェクトを AWS CodePipeline で作成する方法を示します。詳細については、「複数の入力ソースと出力アーティファクトのサンプル」を参照してください。
パイプラインの構造を定義する JSON 形式のファイルを使用して、それを AWS CLI とともに使用してパイプラインを作成することができます。複数の入力ソースと複数の出力アーティファクトを含むビルドを作成するパイプライン構造の例として、次の JSON ファイルを使用してください。このサンプルの後半では、このファイルが複数の入力と出力をどのように指定しているかが分かります。詳細については、『AWS CodePipeline ユーザーガイド』の「CodePipeline パイプライン構造リファレンス」を参照してください。
{
"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": "artifact1
"
},
{
"name": "artifact2
"
}
],
"configuration": {
"ProjectName": "my-build-project-name
",
"PrimarySource": "source1
"
},
"runOrder": 1
}
]
}
],
"artifactStore": {
"type": "S3",
"location": "AWS-CodePipeline-internal-bucket-name
"
},
"name": "my-pipeline-name
",
"version": 1
}
}
この JSON ファイルの制約事項:
-
入力ソースの 1 つを
PrimarySource
に指定する必要があります。このソースは、CodeBuild が buildspec ファイルを探して実行するディレクトリです。キーワードPrimarySource
は、JSON ファイルの CodeBuild ステージのconfiguration
セクションにプライマリソースを指定するのに使用されます。 -
各入力ソースは、それぞれのディレクトリにインストールされます。このディレクトリは、組み込み環境変数
$CODEBUILD_SRC_DIR
(プライマリソースの場合) と$CODEBUILD_SRC_DIR_yourInputArtifactName
(他のすべてのソースの場合) に保存されます。このサンプルのパイプラインでは、2 つの入力ソースディレクトリは$CODEBUILD_SRC_DIR
と$CODEBUILD_SRC_DIR_source2
です。詳細については、「ビルド環境の環境変数」を参照してください。 -
パイプラインの JSON ファイルで指定されている出力成果物の名前は、buildspec ファイルで定義されているセカンダリアーティファクトの名前と一致していなければなりません。このパイプラインは、次の buildspec ファイルを使用します。詳細については、「buildspec の構文」を参照してください。
version: 0.2 phases: build: commands: - touch source1_file - cd $CODEBUILD_SRC_DIR_source2 - touch source2_file artifacts: files: - '**/*' secondary-artifacts: artifact1: base-directory: $CODEBUILD_SRC_DIR files: - source1_file artifact2: base-directory: $CODEBUILD_SRC_DIR_source2 files: - source2_file
JSON ファイルを作成したら、パイプラインを作成することができます。AWS CLI を使用して create-pipeline コマンドを実行し、ファイルを --cli-input-json
パラメータに渡します。詳細については、『AWS CodePipeline ユーザーガイド』の「パイプラインの作成 (CLI)」を参照してください。