本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Amazon CodePipeline集成 CodeBuild 多个输入源和输出工件示例
Amazon CodeBuild 项目可以接受多个输入源,也可以创建多个输出构件。此示例演示如何使用 Amazon CodePipeline 创建一个使用多输入源创建多输出构件的构建项目。有关更多信息,请参阅多输入源和输出构件示例:
您可以使用定义管道结构的 JSON 格式文件,然后将其与 Amazon CLI 配合使用来创建管道。使用以下 JSON 文件作为管道结构的示例,此管道结构创建一个具有多输入源和多输出项目的构建。稍后,此示例会介绍该文件如何指定多个输入和输出。有关更多信息,请参阅《Amazon 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 文件中:
-
必须将输入源之一指定为
PrimarySource
。这个源代码是 CodeBuild 查找和运行你的buildspec文件的目录。关键字PrimarySource
用于指定 JSON 文件中 CodeBuild 阶段configuration
部分的主要来源。 -
每个输入源都安装在各自的目录中。此目录存储在内置环境变量
$CODEBUILD_SRC_DIR
(对于主源)和$CODEBUILD_SRC_DIR_yourInputArtifactName
(对于所有其他源)中。对于此示例中的管道,两个输入源目录为$CODEBUILD_SRC_DIR
和$CODEBUILD_SRC_DIR_source2
。有关更多信息,请参阅构建环境中的环境变量: -
管道的 JSON 文件中指定的输出构件的名称必须与 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 文件后,可以创建管道。使用 Amazon CLI 运行 create-pipeline 命令并将此文件传递给 --cli-input-json
参数。有关更多信息,请参阅Amazon CodePipeline用户指南中的创建管道 (CLI)。