

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

# Filter GitLab Webhook 事件 （主控台）
<a name="gitlab-webhook-events-console"></a>

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

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.  選擇 **Add filter group (新增篩選群組)** 新增另一個篩選群組。

 如需詳細資訊，請參閱《 *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-gitlab.png)


在有兩個篩選群組的範例中，當一個或兩個篩選群組評估為 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-gitlab.png)


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

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


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

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


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

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


在此範例中，Webhook 篩選條件群組只會在 GitLab 使用者所做的變更中觸發組建，而該使用者的帳戶 ID 不符合規則表達式 `actor-account-id`。

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

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


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

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