

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

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

 若要使用 AWS 管理主控台 篩選 Webhook 事件：

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-bitbucket.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-bitbucket.png)


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

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


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

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

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


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

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