

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

# 篩選 GitHub Webhook 事件 (主控台)
<a name="github-webhook-events-console"></a>

使用以下指示，使用 篩選 GitHub Webhook 事件 AWS 管理主控台。如需 GitHub Webhook 事件的詳細資訊，請參閱 [GitHub Webhook 事件](github-webhook.md)。

在**主要來源 Webhook 事件**中，選取下列項目。只有當您在**我的 GitHub 帳戶中為來源儲存庫**選擇儲存庫時，才能使用本節。

1. 當您建立專案時，請選取 **Rebuild every time a code change is pushed to this repository (在每次將程式碼變更推送至此儲存庫時重建)**。

1. 從 **Event type (事件類型)**，選擇一或多個事件。

1. 若要篩選事件觸發組建的時間，請在 **Start a build under these conditions (在這些情況下開始組建)** 下新增一或多個選用的篩選條件。

1. 若要篩選何時不觸發事件，請在 **Don't start a build under these conditions (在這些情況下不開始組建)** 下新增一或多個選用的篩選條件。

1. 如有需要，請選擇**新增篩選條件群組**以新增另一個篩選條件群組。

 如需詳細資訊，請參閱《 *AWS CodeBuild API 參考*》中的 [建立組建專案 (主控台)](create-project.md#create-project-console)和 [WebhookFilter](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_WebhookFilter.html)。

在這個範例中，Webhook 篩選群組僅針對提取請求觸發組建：

![\[僅針對提取請求觸發組建的 Webhook 篩選群組。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/pull-request-webhook-filter.png)


在有兩個 Webhook 篩選群組的範例中，當一個或兩個篩選群組評估為 true 時，就會觸發組建：
+ 第一個篩選群組指定在分支上建立、更新或重新開啟的提取請求，並且這些分支的 Git 參考名稱符合規則表達式 `^refs/heads/main$`，而標頭參考符合 `^refs/heads/branch1$`。
+ 第二個篩選群組在分支上指定推送請求，並且這些分支的 Git 參考名稱符合規則表達式 `^refs/heads/branch1$`。

![\[兩個篩選群組的範例。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/pull-request-webhook-filter-head-base-regexes.png)


在這個範例中，Webhook 篩選群組針對所有請求 (標籤事件除外) 觸發組建。

![\[Webhook 篩選條件群組，可針對標籤事件以外的所有請求觸發組建。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/pull-request-webhook-filter-exclude.png)


在這個範例中，只有在檔案名稱符合規則表達式 `^buildspec.*` 的檔案變更時，Webhook 篩選群組才會觸發組建。

![\[只有當檔案的名稱符合指定的規則表達式時，才會觸發組建的 Webhook 篩選條件群組。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/pull-request-webhook-filter-file-name-regex.png)


在此範例中，Webhook 篩選群組只會在 `src`或 `test` 資料夾中變更檔案時觸發組建。

![\[只有在指定資料夾中變更檔案時，才會觸發組建的 Webhook 篩選群組。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/pull-request-webhook-filter-file-name-combined-regex.png)


在這個範例中，只有當指定的 GitHub 或 GitHub Enterprise Server 使用者進行變更，而且其帳戶 ID 符合規則表達式 `actor-account-id` 時，Webhook 篩選群組才會觸發建置。

**注意**  
 有關如何尋找您的 GitHub 帳戶 ID 的資訊，請參閱 https://api.github.com/users/*user-name*，其中 *user-name* 是您的 GitHub 使用者名稱。

![\[只有當指定的 GitHub 使用者使用符合規則表達式的帳戶 ID 進行變更時，才會觸發組建的 Webhook 篩選群組。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/pull-request-webhook-filter-actor.png)


在此範例中，當 head 提交訊息符合規則運算式 `\[CodeBuild\]` 時，webhook 篩選群組會觸發推送事件的建置。

![\[當前端遞交訊息符合規則表達式時，觸發推送事件建置的 Webhook 篩選條件群組。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/pull-request-webhook-filter-commit-message.png)


在此範例中，Webhook 篩選群組只會觸發 GitHub Actions 工作流程任務事件的組建。

**注意**  
CodeBuild 只有在 Webhook 具有包含 **WORKFLOW\$1JOB\$1QUEUED** 事件篩選條件的篩選條件群組時，才會處理 GitHub Actions 工作流程任務。

![\[Webhook 篩選群組只會觸發 GitHub Actions 工作流程任務事件的組建。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/github-actions-workflow-job-queued-no-highlight.png)


在此範例中，Webhook 篩選群組會為符合規則表達式 的工作流程名稱觸發組建`CI-CodeBuild`。

![\[Webhook 篩選條件群組會為符合規則表達式的工作流程名稱觸發組建。\]](http://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/images/github-actions-workflow-job-specific.png)
