管道声明 - Amazon CodePipeline
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

管道声明

管道和管道元数据层的基本结构包括以下参数和语法。管道参数表示管道中要执行的操作和阶段的结构。

有关更多信息,请参阅《CodePipeline API 指南》中的 PipelineDeclaration 对象。

下面的示例以 JSON 和 YAML 两种格式显示了 V2 类型管道的管道和元数据层结构。

YAML
pipeline: name: MyPipeline roleArn: >- arn:aws:iam::ACCOUNT_ID:role/service-role/AWSCodePipelineServiceRole-us-west-2-MyPipeline artifactStore: type: S3 location: amzn-s3-demo-bucket stages: ... version: 6 executionMode: SUPERSEDED pipelineType: V2 variables: - name: MyVariable defaultValue: '1' triggers: - providerType: CodeStarSourceConnection gitConfiguration: sourceActionName: Source push: - branches: includes: - main excludes: - feature-branch pullRequest: - events: - CLOSED branches: includes: - main* metadata: pipelineArn: 'arn:aws:codepipeline:us-west-2:ACCOUNT_ID:MyPipeline' created: '2019-12-12T06:49:02.733000+00:00' updated: '2020-09-10T06:34:07.447000+00:00' pollingDisabledAt: '2020-09-10T06:34:07.447000+00:00'
JSON
{ "pipeline": { "name": "MyPipeline", "roleArn": "arn:aws:iam::ACCOUNT_ID:role/service-role/AWSCodePipelineServiceRole-us-west-2-MyPipeline", "artifactStore": { "type": "S3", "location": "amzn-s3-demo-bucket" }, "stages": { ... }, "version": 6, "executionMode": "SUPERSEDED", "pipelineType": "V2", "variables": [ { "name": "MyVariable", "defaultValue": "1" } ], "triggers": [ { "providerType": "CodeStarSourceConnection", "gitConfiguration": { "sourceActionName": "Source", "push": [ { "branches": { "includes": [ "main" ], "excludes": [ "feature-branch" ] } } ], "pullRequest": [ { "events": [ "CLOSED" ], "branches": { "includes": [ "main*" ] } } ] } } ] }, "metadata": { "pipelineArn": "arn:aws:codepipeline:us-west-2:ACCOUNT_ID:MyPipeline", "created": "2019-12-12T06:49:02.733000+00:00", "updated": "2020-09-10T06:34:07.447000+00:00", "pollingDisabledAt": "2020-09-10T06:34:07.447000+00:00" } }

name

管道的名称。在编辑或更新管道时,无法更改管道名称。

注意

如果要重命名现有的管道,您可以使用 CLI get-pipeline 命令生成包含管道结构的 JSON 文件。然后,您可以使用 CLI create-pipeline 命令创建具有该结构的新管道,并为其指定新名称。

roleArn

CodePipeline 服务角色的 IAM ARN,如 arn:aws:iam::80398EXAMPLE:role/CodePipeline_Service_Role。

要使用控制台查看管道服务角色 ARN 而不是 JSON 结构,请在控制台中选择管道,然后选择设置。在常规选项卡下,将显示服务角色 ARN 字段。

artifactStore OR artifactStores

artifactStore 字段包含所有操作位于同一 Amazon 区域中的管道的构件桶类型和位置。如果您在与管道不同的区域中添加操作,则 artifactStores 映射将用于列出执行操作的每个 Amazon 区域的构件桶。当您创建或编辑管道时,管道区域中必须有构件存储桶,然后每个您计划执行操作的区域必须有一个构件存储桶。

注意

在管道结构中,必须在管道中包括 artifactStoreartifactStores,但不能同时使用两者。如果在管道中创建跨区域操作,则必须使用 artifactStores

以下示例显示了一个管道的基本结构,该管道具有跨区域操作并使用 artifactStores 参数:

"pipeline": { "name": "YourPipelineName", "roleArn": "CodePipeline_Service_Role", "artifactStores": { "us-east-1": { "type": "S3", "location": "S3 artifact bucket name, such as amzn-s3-demo-bucket" }, "us-west-2": { "type": "S3", "location": "S3 artifact bucket name, such as amzn-s3-demo-bucket" } }, "stages": [ { ...

type

构件存储桶的位置类型,指定为 Amazon S3。

location

第一次使用控制台创建管道时自动为您生成的 Amazon S3 存储桶的名称,如 codepipeline-us-east-2-1234567890,或您为此预置的任何 Amazon S3 存储桶的名称

stages

此参数包含管道中每个阶段的名称。有关管道结构阶段级参数和语法的更多信息,请参阅《CodePipeline API 指南》中的 StageDeclaration 对象。

阶段管道结构有以下要求:

  • 一个管道必须包含至少两个阶段。

  • 管道的第一阶段必须包含至少一个源操作。它只能包含源操作。

  • 只有管道的第一阶段才可包含源操作。

  • 每个管道中至少有一个阶段必须包含不是源操作的操作。

  • 管道中的所有阶段名称都必须唯一。

  • 阶段名称不能在 CodePipeline 控制台内编辑。如果您使用 Amazon CLI 编辑阶段名称,并且该阶段包含具有一个或多个秘密参数(例如 OAuth 令牌)的操作,则这些秘密参数的值将不会保留下来。您必须手动输入参数的值(在 Amazon CLI 返回的 JSON 中由四个星号遮替),并将其包含在 JSON 结构中。

重要

非活动时间超过 30 天的管道将禁用管道轮询功能。有关更多信息,请参阅管道结构参考中的 pollingDisabledAt。有关将管道从轮询迁移为基于事件的更改检测的步骤,请参阅更改检测方法

version

每次更新管道时,都会自动生成和更新管道的版本号。

executionMode

您可以设置管道执行模式,这样就可以为连续运行指定管道行为,如排队、取代或以并行模式运行。有关更多信息,请参阅 设置或更改管道执行模式

重要

对于处于 PARALLEL 模式的管道,阶段回滚不可用。同样,具有回滚结果类型的故障条件无法添加到 PARALLEL 模式管道中。

pipelineType

管道类型指定管道中可用的结构和功能,例如 V2 类型管道。有关更多信息,请参阅 管道类型

variables

管道级变量是在管道运行时间创建和解析管道时定义的。有关更多信息,请参阅 变量参考。有关在管道执行时传递的管道级变量的教程,请参阅教程:使用管道级变量

triggers

通过触发器,您可以将管道配置为在特定事件类型或筛选的事件类型时启动,例如检测到特定分支或拉取请求的更改时。对于使用 CodePipeline 中 CodeStarSourceConnection 操作的连接的源操作(如 GitHub、Bitbucket 和 GitLab),可配置触发器。有关使用连接的源操作的更多信息,请参阅使用 CodeConnections 向管道添加第三方源提供程序

有关更多信息和更多详细示例,请参阅使用触发器和筛选功能自动启动管道

对于筛选,支持 glob 格式的正则表达式模式,详见使用语法中的 glob 模式

注意

CodeCommit 和 S3 源操作需要已配置的更改检测资源(EventBridge 规则),或使用轮询存储库是否有源更改的选项。对于具有 Bitbucket、GitHub 或 GitHub Enterprise Server 源操作的管道,您不必设置 Webhook 或默认进行轮询。连接操作会为您管理更改检测。

重要

非活动时间超过 30 天的管道将禁用管道轮询功能。有关更多信息,请参阅管道结构参考中的 pollingDisabledAt。有关将管道从轮询迁移为基于事件的更改检测的步骤,请参阅更改检测方法

gitConfiguration 字段

触发器的 Git 配置,包括事件类型和任何用于按分支、文件路径、标签或拉取请求事件进行筛选的参数。

JSON 结构中的字段定义如下:

  • sourceActionName:具有 Git 配置的管道源操作的名称。

  • push:使用筛选功能的推送事件。这些事件在不同的推送筛选条件之间使用 OR 运算,在筛选条件内部使用 AND 运算。

    • branches:要筛选的分支。分支在包含和排除之间使用 AND 运算。

      • includes:用于筛选将包含的分支的模式。包含使用 OR 运算。

      • excludes:用于筛选将排除的分支的模式。排除使用 OR 运算。

    • filePaths:要筛选的文件路径名。

      • includes:用于筛选将包含的文件路径的模式。包含使用 OR 运算。

      • excludes:用于筛选将排除的文件路径的模式。排除使用 OR 运算。

    • tags:要筛选的标签名称。

      • includes:用于筛选将包含的标签的模式。包含使用 OR 运算。

      • excludes:用于筛选将排除的标签的模式。排除使用 OR 运算。

  • pullRequest:拉取请求事件,可筛选拉取请求事件和拉取请求筛选条件。

    • events:按指定条件筛选已打开、已更新或已关闭的拉取请求事件。

    • branches:要筛选的分支。分支在包含和排除之间使用 AND 运算。

      • includes:用于筛选将包含的分支的模式。包含使用 OR 运算。

      • excludes:用于筛选将排除的分支的模式。排除使用 OR 运算。

    • filePaths:要筛选的文件路径名。

      • includes:用于筛选将包含的文件路径的模式。包含使用 OR 运算。

      • excludes:用于筛选将排除的文件路径的模式。排除使用 OR 运算。

以下是推送和拉取请求事件类型的触发器配置示例。

"triggers": [ { "provider": "Connection", "gitConfiguration": { "sourceActionName": "ApplicationSource", "push": [ { "filePaths": { "includes": [ "projectA/**", "common/**/*.js" ], "excludes": [ "**/README.md", "**/LICENSE", "**/CONTRIBUTING.md" ] }, "branches": { "includes": [ "feature/**", "release/**" ], "excludes": [ "mainline" ] }, "tags": { "includes": [ "release-v0", "release-v1" ], "excludes": [ "release-v2" ] } } ], "pullRequest": [ { "events": [ "CLOSED" ], "branches": { "includes": [ "feature/**", "release/**" ], "excludes": [ "mainline" ] }, "filePaths": { "includes": [ "projectA/**", "common/**/*.js" ], "excludes": [ "**/README.md", "**/LICENSE", "**/CONTRIBUTING.md" ] } } ] } } ],

包含和排除的事件类型 push 字段

以下列表显示了推送事件类型的 Git 配置字段级别的包含和排除行为:

push (OR operation is used between push and pullRequest or multiples) filePaths (AND operation is used between filePaths, branches, and tags) includes (AND operation is used between includes and excludes) **/FILE.md, **/FILE2 (OR operation is used between file path names) excludes (AND operation is used between includes and excludes) **/FILE.md, **/FILE2 (OR operation is used between file path names) branches (AND operation is used between filePaths, branches, and tags) includes (AND operation is used between includes and excludes) BRANCH/**", "BRANCH2/** (OR operation is used between branch names) excludes (AND operation is used between includes and excludes) BRANCH/**", "BRANCH2/** (OR operation is used between branch names) tags (AND operation is used between filePaths, branches, and tags) includes (AND operation is used between includes and excludes) TAG/**", "TAG2/** (OR operation is used between tag names) excludes (AND operation is used between includes and excludes) TAG/**", "TAG2/** (OR operation is used between tag names)

包含和排除的事件类型 pull request 字段

以下列表显示了拉取请求事件类型的 Git 配置字段级别的包含和排除行为:

pullRequest (OR operation is used between push and pullRequest or multiples) events (AND operation is used between events, filePaths, and branches). Includes/excludes are N/A for pull request events. filePaths (AND operation is used between events, filePaths, and branches) includes (AND operation is used between includes and excludes) **/FILE.md, **/FILE2 (OR operation is used between file path names) excludes (AND operation is used between includes and excludes) **/FILE.md, **/FILE2 (OR operation is used between file path names) branches (AND operation is used between events, filePaths, and branches) includes (AND operation is used between includes and excludes) BRANCH/**", "BRANCH2/** (OR operation is used between branch names) excludes (AND operation is used between includes and excludes) BRANCH/**", "BRANCH2/** (OR operation is used between branch names)

metadata

管道元数据字段与管道结构截然不同,无法进行编辑。在更新管道时,将自动更改 updated 元数据字段中的日期。

pipelineArn

管道的 Amazon 资源名称(ARN)。

要使用控制台查看管道 ARN 而不是 JSON 结构,请在控制台中选择管道,然后选择设置。在常规选项卡下,将显示管道 ARN 字段。

created

创建管道的日期和时间。

updated

上次更新管道的日期和时间。

pollingDisabledAt

对于配置为轮询以检测更改的管道,禁用轮询的日期和时间。

非活动时间超过 30 天的管道将禁用管道轮询功能。

  • 处于非活动状态的管道在连续 30 天没有执行后,其轮询将被禁用。

  • 使用 EventBridge、CodeStar Connections 或 Webhook 的管道不会受到影响。

  • 活跃管道不会受到影响。

有关更多信息,请参阅《CodePipeline API 指南》中的 PipelineMetadata 对象下的 pollingDisabledAt 参数。有关将管道从轮询迁移为基于事件的更改检测的步骤,请参阅更改检测方法