

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

# 管道宣告
<a name="pipeline-requirements"></a>

管道的管道和中繼資料層級具有基本結構，其中包含下列參數和語法。管道參數代表要在管道中執行的動作和階段結構。

如需詳細資訊，請參閱 *CodePipeline * API 指南中的 [PipelineDeclaration](https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_PipelineDeclaration.html) 物件。

下列範例顯示 V2 類型管道的 JSON 和 YAML 中管道結構的管道和中繼資料層級。

------
#### [ 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/CodePipeline\$1Service\$1Role。

若要使用主控台檢視管道服務角色 ARN，而非 JSON 結構，請在主控台中選擇管道，然後選擇**設定**。在**一般**索引標籤下，會顯示**服務角色 ARN** 欄位。

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

`artifactStore` 欄位包含具有相同區域中所有動作之管道的成品儲存貯 AWS 體類型和位置。如果您在與管道不同的區域中新增動作，`artifactStores`映射會用來列出執行動作之每個 AWS 區域的成品儲存貯體。當您建立或編輯管道時，您必須在管道區域中擁有一個成品儲存貯體，然後對於每個您計劃執行動作的區域，都必須擁有一個成品儲存貯體。

**注意**  
在管道結構中，您必須在管道`artifactStores`中包含 `artifactStore`或 ，但不能同時使用兩者。如果您在管道中建立跨區域動作，即必須使用 `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>

觸發可讓您設定管道以啟動特定事件類型或篩選的事件類型，例如偵測到特定分支或提取請求的變更時。對於在 CodePipeline 中使用 動作的連線，例如 GitHub、Bitbucket 和 GitLab，可設定來源`CodeStarSourceConnection`動作的觸發。如需使用連線之來源動作的詳細資訊，請參閱 [使用 CodeConnections 將第三方來源提供者新增至管道](pipelines-connections.md)。

如需詳細資訊和更詳細的範例，請參閱 [使用觸發和篩選來自動化啟動管道](pipelines-triggers.md)。

對於篩選，支援 glob 格式的規則表達式模式，如 中所述[使用語法中的 glob 模式](syntax-glob.md)。

**注意**  
CodeCommit 和 S3 來源動作需要設定的變更偵測資源 (EventBridge 規則），或使用 選項輪詢儲存庫以取得來源變更。對於具有 Bitbucket、GitHub 或 GitHub Enterprise Server 來源動作的管道，您不需要設定 Webhook 或預設輪詢。連線動作會為您管理變更偵測。

**重要**  
處於非作用中狀態超過 30 天的管道會停用管道的輪詢。如需詳細資訊，請參閱管道結構參考中的[pollingDisabledAt](#metadata.pollingDisabledAt)。如需將管道從輪詢遷移至事件型變更偵測的步驟，請參閱[變更偵測方法](change-detection-methods.md)。

### `gitConfiguration` 欄位
<a name="pipeline.triggers.fields"></a>

觸發條件的 Git 組態，包括事件類型，以及依分支、檔案路徑、標籤或提取請求事件進行篩選的任何參數。

JSON 結構中的欄位定義如下：
+ `sourceActionName`：具有 Git 組態的管道來源動作名稱。
+ `push`：具有篩選的推送事件。這些事件會在不同的推送篩選條件和篩選條件內的 AND 操作之間使用 OR 操作。
  + `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 Resource Name (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 Connections 或 Webhook 的管道不會受到影響。
+ 作用中管道不會受到影響。

如需詳細資訊，請參閱 * CodePipeline API 指南*中 [PipelineMetadata](https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_PipelineMetadata.html) 物件下的 `pollingDisabledAt` 參數。如需將管道從輪詢遷移至事件型變更偵測的步驟，請參閱[變更偵測方法](change-detection-methods.md)。