

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 管道声明
<a name="pipeline-requirements"></a>

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

有关更多信息，请参阅 *CodePipeline API 指南*中的[PipelineDeclaration](https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_PipelineDeclaration.html)对象。

下面的示例以 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\$100: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`
<a name="pipeline.name"></a>

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

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

## `roleArn`
<a name="pipeline.roleArn"></a>

 CodePipeline 服务角色的 IAM ARN，例如 arn: aws: iam:: 80398Example: role/ \$1Service\$1Role。CodePipeline

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

## `artifactStore` OR `artifactStores`
<a name="pipeline.artifactStore"></a>

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

**注意**  
在管道结构中，必须在管道中包括 `artifactStore` 或 `artifactStores`，但不能同时使用两者。如果在管道中创建跨区域操作，则必须使用 `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`
<a name="pipeline.artifactstore.type"></a>

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

### `location`
<a name="pipeline.artifactstore.location"></a>

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

## `stages`
<a name="pipeline.stages"></a>

此参数包含管道中每个阶段的名称。有关管道结构阶段级别的参数和语法的更多信息，请参阅 * CodePipeline API 指南*中的[StageDeclaration](https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_StageDeclaration.html)对象。

阶段管道结构有以下要求：
+ 一个管道必须包含至少两个阶段。
+ 管道的第一阶段必须包含至少一个源操作。它只能包含源操作。
+ 只有管道的第一阶段才可包含源操作。
+ 每个管道中至少有一个阶段必须包含不是源操作的操作。
+ 管道中的所有阶段名称都必须唯一。
+ 无法在控制台中编辑舞 CodePipeline 台名称。如果您使用编辑阶段名称 AWS CLI，并且该阶段包含带有一个或多个秘密参数（例如 OAuth 令牌）的操作，则不会保留这些秘密参数的值。您必须手动输入参数的值（在 AWS CLI返回的 JSON 中由四个星号遮替），并将其包含在 JSON 结构中。

**重要**  
非活动时间超过 30 天的管道将禁用管道轮询功能。有关更多信息，请参阅管道结构参考[pollingDisabledAt](#metadata.pollingDisabledAt)中的。有关将管道从轮询迁移为基于事件的更改检测的步骤，请参阅[更改检测方法](change-detection-methods.md)。

## `version`
<a name="pipeline.version"></a>

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

## `executionMode`
<a name="pipeline.executionmode"></a>

您可以设置管道执行模式，这样就可以为连续运行指定管道行为，如排队、取代或以并行模式运行。有关更多信息，请参阅 [设置或更改管道执行模式](execution-modes.md)。

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

## `pipelineType`
<a name="pipeline.pipelineType"></a>

管道类型指定管道中可用的结构和功能，例如 V2 类型管道。有关更多信息，请参阅 [管道类型](pipeline-types.md)。

## `variables`
<a name="pipeline.variables"></a>

管道级变量是在管道运行时间创建和解析管道时定义的。有关更多信息，请参阅 [变量参考](reference-variables.md)。有关在管道执行时传递的管道级变量的教程，请参阅[教程：使用管道级变量](tutorials-pipeline-variables.md)。

## `triggers`
<a name="pipeline.triggers"></a>

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

有关更多信息和更多详细示例，请参阅[使用触发器和筛选功能自动启动管道](pipelines-triggers.md)。

对于筛选，支持 glob 格式的正则表达式模式，详见[使用语法中的 glob 模式](syntax-glob.md)。

**注意**  
 CodeCommit 和 S3 源操作需要配置的更改检测资源（ EventBridge 规则），或者使用选项轮询存储库以获取源更改。对于具有 Bitbucket GitHub、或 E GitHub nterprise Server 源操作的管道，您无需设置 webhook 或默认进行轮询。连接操作会为您管理更改检测。

**重要**  
非活动时间超过 30 天的管道将禁用管道轮询功能。有关更多信息，请参阅管道结构参考[pollingDisabledAt](#metadata.pollingDisabledAt)中的。有关将管道从轮询迁移为基于事件的更改检测的步骤，请参阅[更改检测方法](change-detection-methods.md)。

### `gitConfiguration` 字段
<a name="pipeline.triggers.fields"></a>

触发器的 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` 字段
<a name="w2aac54c27c27c15"></a>

以下列表显示了**推送**事件类型的 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` 字段
<a name="w2aac54c27c27c17"></a>

以下列表显示了**拉取请求**事件类型的 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`
<a name="metadata.top-level"></a>

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

### `pipelineArn`
<a name="metadata.pipelineArn"></a>

管道的 Amazon 资源名称（ARN）。

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

### `created`
<a name="metadata.created"></a>

创建管道的日期和时间。

### `updated`
<a name="metadata.updated"></a>

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

### `pollingDisabledAt`
<a name="metadata.pollingDisabledAt"></a>

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

非活动时间超过 30 天的管道将禁用管道轮询功能。
+ 处于非活动状态的管道在连续 30 天没有执行后，其轮询将被禁用。
+ 使用 EventBridge、 CodeStar 连接或 webhook 的管道不会受到影响。
+ 活跃管道不会受到影响。

有关更多信息，请参阅 * CodePipeline API 指南*中[PipelineMetadata](https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_PipelineMetadata.html)对象下的`pollingDisabledAt`参数。有关将管道从轮询迁移为基于事件的更改检测的步骤，请参阅[更改检测方法](change-detection-methods.md)。