本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
監控 CodePipeline 事件
您可以在 中監控 CodePipeline 事件 EventBridge,從您自己的應用程式、 software-as-a-service (SaaS 應用程式和 AWS 服務. EventBridge routes 將即時資料串流傳遞至目標,例如 AWS Lambda 和 Amazon Simple Notification Service。這些事件與 Amazon CloudWatch Events 中出現的事件相同,它提供近乎即時的系統事件串流,描述 AWS 資源的變更。如需詳細資訊,請參閱 Amazon 使用者指南 EventBridge中的什麼是 Amazon?。 EventBridge
Amazon EventBridge 是管理事件的首選方式。Amazon CloudWatch Events 和 EventBridge 是相同的基礎服務和 API,但 EventBridge 提供了更多功能。您在 CloudWatch 事件或 中所做的變更 EventBridge 會顯示在每個主控台中。
事件由規則組成。規則的設定方式是選擇下列項目:
-
事件模式。每個規則都表示為事件模式,其中包含要監控的事件來源和類型,以及事件目標。若要監控事件,您可以使用您要監控的服務建立規則作為事件來源,例如 CodePipeline。例如,您可以建立具有事件模式的規則,該事件模式會 CodePipeline 用作事件來源,在管道、階段或動作的狀態變更時觸發規則。
-
目標。新的規則收到選取的服務做為事件目標。您可能想要設定目標服務來傳送通知、擷取狀態資訊、採取修正動作、啟動事件或採取其他動作。新增目標時,您還必須授予 許可 EventBridge ,以允許它叫用選取的目標服務。
每種類型的執行狀態變更事件都會發出具有特定訊息內容的通知,其中:
-
初始version
項目會顯示事件的版本編號。
-
detail
管道下的 version
項目會顯示管道結構版本號碼。
-
detail
管道下的 execution-id
項目會顯示導致狀態變更之管道執行的執行 ID。請參閱AWS CodePipeline API參考 中的GetPipelineExecutionAPI呼叫。
-
pipeline-execution-attempt
項目會顯示特定執行 ID 的嘗試次數或重試次數。
CodePipeline 會在 AWS 帳戶 變更中資源狀態 EventBridge 時,將事件回報給 。事件會根據下列資源的保證 at-least-once發出:
事件由 發出, EventBridge 其事件模式和結構描述如上所述。對於已處理的事件,例如您透過在開發人員工具主控台中設定的通知接收的事件,事件訊息會包含具有一些變化的事件模式欄位。例如, detail-type
欄位會轉換為 detailType
。如需詳細資訊,請參閱 Amazon EventBridge API 參考 中的 PutEvents API 呼叫。
下列範例顯示 的事件 CodePipeline。如果可能,每個範例都會顯示發出事件的結構描述,以及已處理事件的結構描述。
詳細資訊類型
當您設定要監控的事件時,您可以選擇事件的詳細資訊類型。
您可以設定要在下列項目的狀態變更時傳送的通知:
-
指定的管道或您的所有管道。使用 "detail-type":
"CodePipeline Pipeline Execution State Change"
,即可控制此項目。
-
指定的階段或您的所有階段,位於指定的管道或您的所有管道內。使用 "detail-type":
"CodePipeline Stage Execution State Change"
,即可控制此項目。
-
指定的動作或所有動作,位在指定管道或您所有管道的指定階段或所有階段內。使用 "detail-type":
"CodePipeline Action Execution State Change"
,即可控制此項目。
發出的事件 EventBridge 包含 detail-type
參數,會在處理事件detailType
時轉換為 。
詳細資訊類型 |
州 |
描述 |
CodePipeline 管道執行狀態變更 |
CANCELED |
已取消管道執行,因為已更新管道結構。 |
FAILED |
管道執行未成功完成。 |
RESUMED |
已針對RetryStageExecution API呼叫重試失敗的管道執行。 |
STARTED |
管道執行目前正在執行。 |
STOPPED |
停止程序已完成,且管道執行已停止。 |
STOPPING |
由於要求停止並等待或停止並捨棄管道執行,因此管道執行正在停止中。 |
SUCCEEDED |
管道執行已成功完成。 |
SUPERSEDED |
雖然此管道執行等待下一個階段完成,但較新的管道執行已改為透過管道前進並繼續。
|
CodePipeline 階段執行狀態變更 |
CANCELED |
已取消階段,因為已更新管道結構。 |
FAILED |
階段未成功完成。 |
RESUMED |
已重試失敗階段以回應RetryStageExecution API呼叫。 |
STARTED |
階段目前正在執行。 |
STOPPED |
停止程序已完成,且階段執行已停止。 |
STOPPING |
由於要求停止並等待或停止並捨棄管道執行,因此階段執行正在停止中。 |
SUCCEEDED |
階段已成功完成。 |
CodePipeline 動作執行狀態變更 |
ABANDONED |
由於要求停止並捨棄管道執行,因而捨棄動作。 |
CANCELED |
已取消動作,因為已更新管道結構。 |
FAILED |
對於核准動作,FAILED狀態表示動作遭到檢閱者拒絕,或因動作組態不正確而失敗。 |
STARTED |
動作目前正在執行。 |
SUCCEEDED |
動作已成功完成。 |
管道層級事件
當管道執行的狀態變更時,就會發出管道層級事件。
管道STARTED事件
當管道執行開始時,它會發出事件,以傳送包含下列內容的通知。此範例適用於 "myPipeline"
us-east-1
區域中名為 的管道。id
欄位代表事件 ID,account
欄位代表建立管道的帳戶 ID。
- Emitted event
-
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Pipeline Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-24T22:03:07Z",
"region": "us-east-1",
"resources": [
"arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"execution-trigger": {
"trigger-type": "StartPipelineExecution",
"trigger-detail": "arn:aws:sts::123456789012:assumed-role/Admin/my-user"
},
"state": "STARTED",
"version": 1.0,
"pipeline-execution-attempt": 1.0
}
}
- Processed event
-
{
"account": "123456789012",
"detailType": "CodePipeline Pipeline Execution State Change",
"region": "us-east-1",
"source": "aws.codepipeline",
"time": "2021-06-24T00:44:50Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/a69c62c21EXAMPLE",
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"execution-trigger": {
"trigger-type": "StartPipelineExecution",
"trigger-detail": "arn:aws:sts::123456789012:assumed-role/Admin/my-user"
},
"state": "STARTED",
"version": 1.0,
"pipeline-execution-attempt": 1.0
},
"resources": [
"arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
],
"additionalAttributes": {}
}
管道STOPPING事件
當管道執行停止時,它會發出事件,以傳送包含下列內容的通知。此範例適用於 myPipeline
us-west-2
區域中名為 的管道。
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Pipeline Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-24T22:02:20Z",
"region": "us-west-2",
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"state": "STOPPING",
"version": 3.0,
"pipeline-execution-attempt": 1.0
"stop-execution-comments": "Stopping the pipeline for an update"
}
}
管道SUCCEEDED事件
當管道執行成功時,它會發出事件,以傳送包含下列內容的通知。此範例適用於 myPipeline
us-east-1
區域中名為 的管道。
- Emitted event
-
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Pipeline Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-24T22:03:44Z",
"region": "us-east-1",
"resources": [
"arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"state": "SUCCEEDED",
"version": 3.0,
"pipeline-execution-attempt": 1.0
}
}
- Processed event
-
{
"account": "123456789012",
"detailType": "CodePipeline Pipeline Execution State Change",
"region": "us-east-1",
"source": "aws.codepipeline",
"time": "2021-06-30T22:13:51Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"state": "SUCCEEDED",
"version": 1.0,
"pipeline-execution-attempt": 1.0
},
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"additionalAttributes": {}
}
管道 SUCCEEDED(Git 標籤的範例)
當管道執行的階段已重試並成功時,它會發出事件,以傳送包含下列內容的通知。此範例適用於名為 myPipeline
的管道,該管道execution-trigger
位於 為 Git 標籤設定的eu-central-1
區域中。
execution-trigger
欄位將具有 tag-name
或 branch-name
,取決於觸發管道的事件類型。
{
"version": "0",
"id": "b128b002-09fd-4574-4eba-27152726c777",
"detail-type": "CodePipeline Pipeline Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2023-10-26T13:50:53Z",
"region": "eu-central-1",
"resources": [
"arn:aws:codepipeline:eu-central-1:123456789012:BuildFromTag"
],
"detail": {
"pipeline": "BuildFromTag",
"execution-id": "e17b5773-cc0d-4db2-9ad7-594c73888de8",
"start-time": "2023-10-26T13:49:39.208Z",
"execution-trigger": {
"author-display-name": "Mary Major",
"full-repository-name": "mmajor/sample-project",
"provider-type": "GitLab",
"author-email": "email_address",
"commit-message": "Update file README.md",
"author-date": "2023-08-16T21:08:08Z",
"tag-name": "gitlab-v4.2.1",
"commit-id": "commit_ID
",
"connection-arn": "arn:aws:codestar-connections:eu-central-1:123456789012:connection/0f5b706a-1a1d-46c5-86b6-f177321bcfb2",
"author-id": "Mary Major"
},
"state": "SUCCEEDED",
"version": 32.0,
"pipeline-execution-attempt": 1.0
}
}
管道FAILED事件
當管道執行失敗時,它會發出事件,以傳送包含下列內容的通知。此範例適用於 "myPipeline"
us-west-2
區域中名為 的管道。
- Emitted event
-
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Pipeline Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-31T18:55:43Z",
"region": "us-west-2",
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"state": "FAILED",
"version": 4.0,
"pipeline-execution-attempt": 1.0
}
}
- Processed event
-
{
"account": "123456789012",
"detailType": "CodePipeline Pipeline Execution State Change",
"region": "us-west-2",
"source": "aws.codepipeline",
"time": "2021-06-24T00:46:16Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"state": "FAILED",
"version": 1.0,
"pipeline-execution-attempt": 1.0
},
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"additionalAttributes": {
"failedActionCount": 1,
"failedActions": [
{
"action": "Deploy",
"additionalInformation": "Deployment <ID> failed"
}
],
"failedStage": "Deploy"
}
管道 FAILED(Git 標籤的範例)
除非在來源階段失敗,否則對於使用觸發條件設定的管道,它會發出事件,以下列內容傳送通知。此範例適用於名為 myPipeline
的管道,該管道execution-trigger
位於 為 Git 標籤設定的eu-central-1
區域中。
execution-trigger
欄位將具有 tag-name
或 branch-name
,取決於觸發管道的事件類型。
- Emitted event
-
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Pipeline Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-31T18:55:43Z",
"region": "us-west-2",
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"execution-trigger": {
"author-display-name": "Mary Major",
"full-repository-name": "mmajor/sample-project",
"provider-type": "GitLab",
"author-email": "email_address",
"commit-message": "Update file README.md",
"author-date": "2023-08-16T21:08:08Z",
"tag-name": "gitlab-v4.2.1",
"commit-id": "commit_ID
",
"connection-arn": "arn:aws:codestar-connections:eu-central-1:123456789012:connection/0f5b706a-1a1d-46c5-86b6-f177321bcfb2",
"author-id": "Mary Major"
},
"state": "FAILED",
"version": 4.0,
"pipeline-execution-attempt": 1.0
}
}
- Processed event
-
{
"account": "123456789012",
"detailType": "CodePipeline Pipeline Execution State Change",
"region": "us-west-2",
"source": "aws.codepipeline",
"time": "2021-06-24T00:46:16Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"execution-trigger": {
"author-display-name": "Mary Major",
"full-repository-name": "mmajor/sample-project",
"provider-type": "GitLab",
"author-email": "email_address",
"commit-message": "Update file README.md",
"author-date": "2023-08-16T21:08:08Z",
"tag-name": "gitlab-v4.2.1",
"commit-id": "commit_ID
",
"connection-arn": "arn:aws:codestar-connections:eu-central-1:123456789012:connection/0f5b706a-1a1d-46c5-86b6-f177321bcfb2",
"author-id": "Mary Major"
},
"state": "FAILED",
"version": 1.0,
"pipeline-execution-attempt": 1.0
},
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"additionalAttributes": {
"failedActionCount": 1,
"failedActions": [
{
"action": "Deploy",
"additionalInformation": "Deployment <ID> failed"
}
],
"failedStage": "Deploy"
}
階段層級事件
當階段執行的狀態變更時,會發出階段層級事件。
階段STARTED事件
階段執行開始時,會發出事件,以傳送包含下列內容的通知。此範例適用於"myPipeline"
在 us-east-1
區域中名為 的管道,適用於階段 Prod
。
- Emitted event
-
{
"version": "0",
"id": 01234567-EXAMPLE,
"detail-type": "CodePipeline Stage Execution State Change",
"source": "aws.codepipeline",
"account": 123456789012,
"time": "2020-01-24T22:03:07Z",
"region": "us-east-1",
"resources": [
"arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"version": 1.0,
"execution-id": 12345678-1234-5678-abcd-12345678abcd,
"start-time": "2023-10-26T13:49:39.208Z",
"stage": "Prod",
"state": "STARTED",
"pipeline-execution-attempt": 1.0
}
}
- Processed event
-
{
"account": "123456789012",
"detailType": "CodePipeline Stage Execution State Change",
"region": "us-east-1",
"source": "aws.codepipeline",
"time": "2021-06-24T00:45:40Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"stage": "Source",
"state": "STARTED",
"version": 1.0,
"pipeline-execution-attempt": 0.0
},
"resources": [
"arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
],
"additionalAttributes": {
"sourceActions": [
{
"sourceActionName": "Source",
"sourceActionProvider": "CodeCommit",
"sourceActionVariables": {
"BranchName": "main",
"CommitId": "<ID>",
"RepositoryName": "my-repo"
}
}
]
}
}
階段STOPPING事件
當階段執行停止時,會發出事件,以傳送包含下列內容的通知。此範例適用於myPipeline
在 us-west-2
區域中名為 的管道,適用於階段 Deploy
。
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Stage Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-24T22:02:20Z",
"region": "us-west-2",
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"stage": "Deploy",
"state": "STOPPING",
"version": 3.0,
"pipeline-execution-attempt": 1.0
}
}
階段STOPPED事件
當階段執行停止時,會發出事件,以傳送包含下列內容的通知。此範例適用於myPipeline
在 us-west-2
區域中名為 的管道,適用於階段 Deploy
。
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Stage Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-31T18:21:39Z",
"region": "us-west-2",
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:49:39.208Z",
"stage": "Deploy",
"state": "STOPPED",
"version": 3.0,
"pipeline-execution-attempt": 1.0
}
}
階段RESUMED後重試事件
當階段執行恢復且具有已重試的階段時,會發出事件,以傳送包含下列內容的通知。
重試階段後,stage-last-retry-attempt-time
欄位會顯示,如範例所示。如果已執行重試,則欄位會顯示在所有階段事件上。
重試階段後, stage-last-retry-attempt-time
欄位會出現在所有後續階段事件中。
{
"version": "0",
"id": "38656bcd-a798-5f92-c738-02a71be484e1",
"detail-type": "CodePipeline Stage Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2023-10-26T14:14:56Z",
"region": "eu-central-1",
"resources": [
"arn:aws:codepipeline:eu-central-1:123456789012:BuildFromTag"
],
"detail": {
"pipeline": "BuildFromTag",
"execution-id": "05dafb6a-5a56-4951-a858-968795364846",
"stage-last-retry-attempt-time": "2023-10-26T14:14:56.305Z",
"stage": "Build",
"state": "RESUMED",
"version": 32.0,
"pipeline-execution-attempt": 2.0
}
}
動作層級事件
當動作執行有狀態變更時,會發出動作層級事件。
動作STARTED事件
動作執行開始時,它會發出事件,以傳送包含下列內容的通知。此範例適用於myPipeline
在 us-east-1
區域中名為 的管道,適用於部署動作 myAction
。
- Emitted event
-
{
"version": "0",
"id": 01234567-EXAMPLE,
"detail-type": "CodePipeline Action Execution State Change",
"source": "aws.codepipeline",
"account": 123456789012,
"time": "2020-01-24T22:03:07Z",
"region": "us-east-1",
"resources": [
"arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": 12345678-1234-5678-abcd-12345678abcd,
"start-time": "2023-10-26T13:51:09.981Z",
"stage": "Prod",
"action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
"action": "myAction",
"state": "STARTED",
"type": {
"owner": "AWS",
"category": "Deploy",
"provider": "CodeDeploy",
"version": "1"
},
"version": 2.0
"pipeline-execution-attempt": 1.0
"input-artifacts": [
{
"name": "SourceArtifact",
"s3location": {
"bucket": "codepipeline-us-east-1-BUCKETEXAMPLE",
"key": "myPipeline/SourceArti/KEYEXAMPLE"
}
}
]
}
}
- Processed event
-
{
"account": "123456789012",
"detailType": "CodePipeline Action Execution State Change",
"region": "us-west-2",
"source": "aws.codepipeline",
"time": "2021-06-24T00:45:44Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:51:09.981Z",
"stage": "Deploy",
"action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
"action": "Deploy",
"input-artifacts": [
{
"name": "SourceArtifact",
"s3location": {
"bucket": "codepipeline-us-east-1-EXAMPLE",
"key": "myPipeline/SourceArti/EXAMPLE"
}
}
],
"state": "STARTED",
"region": "us-east-1",
"type": {
"owner": "AWS",
"provider": "CodeDeploy",
"category": "Deploy",
"version": "1"
},
"version": 1.0,
"pipeline-execution-attempt": 1.0
},
"resources": [
"arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
],
"additionalAttributes": {}
}
動作SUCCEEDED事件
當動作執行成功時,它會發出事件,以傳送包含下列內容的通知。此範例適用於"myPipeline"
名為 us-west-2
區域的管道,適用於來源動作 "Source"
。對於此事件類型,有兩個不同的region
欄位。事件region
欄位指定管道事件的區域。detail
區段下方的region
欄位會指定動作的區域。
- Emitted event
-
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Action Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-24T22:03:11Z",
"region": "us-west-2",
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:51:09.981Z",
"stage": "Source",
"execution-result": {
"external-execution-url": "https://us-west-2.console.aws.amazon.com/codecommit/home#/repository/my-repo/commit/8cf40f2EXAMPLE",
"external-execution-summary": "Added LICENSE.txt",
"external-execution-id": "8cf40fEXAMPLE"
},
"output-artifacts": [
{
"name": "SourceArtifact",
"s3location": {
"bucket": "codepipeline-us-west-2-BUCKETEXAMPLE",
"key": "myPipeline/SourceArti/KEYEXAMPLE"
}
}
],
"action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
"action": "Source",
"state": "SUCCEEDED",
"region": "us-west-2",
"type": {
"owner": "AWS",
"provider": "CodeCommit",
"category": "Source",
"version": "1"
},
"version": 3.0,
"pipeline-execution-attempt": 1.0
}
}
- Processed event
-
{
"account": "123456789012",
"detailType": "CodePipeline Action Execution State Change",
"region": "us-west-2",
"source": "aws.codepipeline",
"time": "2021-06-24T00:45:44Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:ACCOUNT:notificationrule/a69c62c21EXAMPLE",
"detail": {
"pipeline": "myPipeline",
"execution-id": "arn:aws:codepipeline:us-west-2:123456789012:myPipeline",
"start-time": "2023-10-26T13:51:09.981Z",
"stage": "Source",
"execution-result": {
"external-execution-url": "https://us-west-2.console.aws.amazon.com/codecommit/home#/repository/my-repo/commit/8cf40f2EXAMPLE",
"external-execution-summary": "Edited index.html",
"external-execution-id": "36ab3ab7EXAMPLE"
},
"output-artifacts": [
{
"name": "SourceArtifact",
"s3location": {
"bucket": "codepipeline-us-west-2-EXAMPLE",
"key": "myPipeline/SourceArti/EXAMPLE"
}
}
],
"action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
"action": "Source",
"state": "SUCCEEDED",
"region": "us-west-2",
"type": {
"owner": "AWS",
"provider": "CodeCommit",
"category": "Source",
"version": "1"
},
"version": 1.0,
"pipeline-execution-attempt": 1.0
},
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"additionalAttributes": {}
}
動作FAILED事件
當動作執行失敗時,它會發出事件,以傳送包含下列內容的通知。此範例適用於 "myPipeline"
us-west-2
區域中名為 的管道,適用於動作 "Deploy"
。
- Emitted event
-
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Action Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-31T18:55:43Z",
"region": "us-west-2",
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"start-time": "2023-10-26T13:51:09.981Z",
"stage": "Deploy",
"execution-result": {
"external-execution-url": "https://us-west-2.console.aws.amazon.com/codedeploy/home?#/deployments/<ID>",
"external-execution-summary": "Deployment <ID> failed",
"external-execution-id": "<ID>",
"error-code": "JobFailed"
},
"action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
"action": "Deploy",
"state": "FAILED",
"region": "us-west-2",
"type": {
"owner": "AWS",
"provider": "CodeDeploy",
"category": "Deploy",
"version": "1"
},
"version": 4.0,
"pipeline-execution-attempt": 1.0
}
}
- Processed event
-
{
"account": "123456789012",
"detailType": "CodePipeline Action Execution State Change",
"region": "us-west-2",
"source": "aws.codepipeline",
"time": "2021-06-24T00:46:16Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"stage": "Deploy",
"execution-result": {
"external-execution-url": "https://console.aws.amazon.com/codedeploy/home?region=us-west-2#/deployments/<ID>",
"external-execution-summary": "Deployment <ID> failed",
"external-execution-id": "<ID>",
"error-code": "JobFailed"
},
"action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
"action": "Deploy",
"state": "FAILED",
"region": "us-west-2",
"type": {
"owner": "AWS",
"provider": "CodeDeploy",
"category": "Deploy",
"version": "1"
},
"version": 13.0,
"pipeline-execution-attempt": 1.0
},
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"additionalAttributes": {
"additionalInformation": "Deployment <ID> failed"
}
}
動作ABANDONED事件
放棄動作執行時,會發出事件,以傳送包含下列內容的通知。此範例適用於 "myPipeline"
us-west-2
區域中名為 的管道,適用於動作 "Deploy"
。
{
"version": "0",
"id": "01234567-EXAMPLE",
"detail-type": "CodePipeline Action Execution State Change",
"source": "aws.codepipeline",
"account": "123456789012",
"time": "2020-01-31T18:21:39Z",
"region": "us-west-2",
"resources": [
"arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
],
"detail": {
"pipeline": "myPipeline",
"execution-id": "12345678-1234-5678-abcd-12345678abcd",
"stage": "Deploy",
"action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
"action": "Deploy",
"state": "ABANDONED",
"region": "us-west-2",
"type": {
"owner": "AWS",
"provider": "CodeDeploy",
"category": "Deploy",
"version": "1"
},
"version": 3.0,
"pipeline-execution-attempt": 1.0
}
}
建立在管道事件上傳送通知的規則
規則會監控特定事件,然後將其路由至您選擇的 AWS 目標。您可以建立規則,在發生其他 AWS 動作時自動執行 AWS 動作,或建立規則,以設定排程定期執行 AWS 動作。
管道狀態變更時傳送通知 (主控台)
這些步驟說明如何使用 EventBridge 主控台建立規則,以傳送 中變更的通知 CodePipeline。
使用 Amazon S3 來源建立以管道為目標的 EventBridge 規則
在 開啟 Amazon EventBridge 主控台https://console.aws.amazon.com/events/。
-
在導覽窗格中,選擇規則。保持選取預設匯流排,或選取事件匯流排。選擇建立規則。
-
在名稱 中,輸入規則的名稱。
-
在規則類型 下,選擇具有事件模式 的規則。選擇 Next (下一步)。
-
在事件模式 下,選擇AWS 服務 。
-
從 Event Type (事件類型) 下拉式清單中,選擇通知的狀態變更層級。
-
如需套用至管道層級事件的規則,請選擇CodePipeline管道執行狀態變更 。
-
如需套用至階段層級事件的規則,請選擇CodePipeline階段執行狀態變更 。
-
如需套用至動作層級事件的規則,請選擇CodePipeline動作執行狀態變更 。
-
指定規則套用至的狀態變更:
-
對於超出選取器允許範圍的事件模式,您也可以使用事件模式視窗中的編輯模式選項,以JSON格式指定事件模式。
如果未另外指定,則會為所有 pipelines/stages/actions和 狀態建立事件模式。
如需更詳細的事件模式,您可以將下列範例事件模式複製並貼到事件模式視窗中。
-
使用此範例事件模式,擷取所有管道的失敗部署和建置動作。
{
"source": [
"aws.codepipeline"
],
"detail-type": [
"CodePipeline Action Execution State Change"
],
"detail": {
"state": [
"FAILED"
],
"type": {
"category": ["Deploy", "Build"]
}
}
}
-
使用此範例事件模式,擷取所有管道的所有已拒絕或失敗核准動作。
{
"source": [
"aws.codepipeline"
],
"detail-type": [
"CodePipeline Action Execution State Change"
],
"detail": {
"state": [
"FAILED"
],
"type": {
"category": ["Approval"]
}
}
}
-
{
"source": [
"aws.codepipeline"
],
"detail-type": [
"CodePipeline Pipeline Execution State Change",
"CodePipeline Action Execution State Change",
"CodePipeline Stage Execution State Change"
],
"detail": {
"pipeline": ["myPipeline", "my2ndPipeline"]
}
}
-
選擇 Next (下一步)。
-
在目標類型 中,選擇AWS 服務 。
-
在選取目標 中,選擇 CodePipeline。在管道 ARN中,輸入此規則要啟動ARN的管道管道。
若要取得管道 ARN,請執行 get-pipeline命令。管道ARN會出現在輸出中。其建構格式如下:
arn:aws:codepipeline:region
:account
:pipeline-name
範例管道ARN:
arn:aws:codepipeline:us-east-2:80398EXAMPLE:MyFirstPipeline
-
若要建立或指定IAM服務角色,以授予 EventBridge 許可來叫用與 EventBridge 規則相關聯的目標 (在此情況下,目標為 CodePipeline):
-
選擇 Next (下一步)。
-
在標籤頁面上,選擇下一個 。
-
在檢閱和建立頁面上,檢閱規則組態。如果您對此規則感到滿意,請選擇 Create rule (建立規則)。
管道狀態變更時傳送通知 (CLI)
這些步驟說明如何使用 CLI建立 CloudWatch 事件規則,以傳送 中變更的通知 CodePipeline。
若要使用 AWS CLI 建立規則,請呼叫 put-rule命令,指定:
若要使用 建立 EventBridge 規則 CodePipeline 作為事件來源
-
呼叫 put-rule 命令,以建立規則並指定事件模式 (如需有效狀態,請參閱上述各表)。
下列範例命令使用 --event-pattern建立稱為 的規則“MyPipelineStateChanges”
,當名為 "" 的管道的管道執行失敗時,該規則會發出 CloudWatch 事件myPipeline。
aws events put-rule --name "MyPipelineStateChanges" --event-pattern "{\"source\":[\"aws.codepipeline\"],\"detail-type\":[\"CodePipeline Pipeline Execution State Change\"],\"detail\":{\"pipeline\":[\"myPipeline\"],\"state\":[\"FAILED\"]}}"
-
呼叫 put-targets命令並包含下列參數:
以下命令範例指定名為 MyPipelineStateChanges
的規則,該目標 Id
是由數字 1 組成,指出在規則的目標清單中,這是目標 1。範例命令也會指定 Amazon SNS主題ARN
的範例。
aws events put-targets --rule MyPipelineStateChanges --targets Id=1,Arn=arn:aws:sns:us-west-2:11111EXAMPLE:MyNotificationTopic
-
新增 的許可 EventBridge ,以使用指定的目標服務來叫用通知。如需詳細資訊,請參閱使用 Amazon 的資源型政策 EventBridge。