监视 CodePipeline 事件 - Amazon CodePipeline
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

监视 CodePipeline 事件

您可以在中监控 CodePipeline 事件 EventBridge,它会提供来自您自己的应用程序、 software-as-a-service (SaaS) 应用程序和的实时数据流 Amazon Web Services 服务。 EventBridge 将该数据路由到目标,例如 Amazon Lambda 和 Amazon 简单通知服务。这些事件与 Amazon Events 中显示 CloudWatch 的事件相同,后者提供描述 Amazon 资源变化的近乎实时的系统事件流。有关更多信息,请参阅什么是亚马逊 EventBridge? 在《亚马逊 EventBridge 用户指南》中。

注意

Amazon EventBridge 是管理您的活动的首选方式。Amazon CloudWatch Events 和API, EventBridge 是相同的基础服务,但 EventBridge 提供了更多功能。您在 CloudWatch 活动中所做的更改或 EventBridge 将显示在每个控制台中。

事件由规则组成。通过选择以下选项来配置规则:

  • 事件模式。每条规则都以事件模式表示,其中包含要监控的事件的来源和类型以及事件目标。要监控事件,您需要创建一条规则,将所监视的服务作为事件源,例如 CodePipeline。例如,您可以创建一个带有事件模式的规则,当管道、阶段或操作的状态发生变化时,该事件模式 CodePipeline 用作事件源来触发规则。

  • 目标。新规则将选定的服务作为事件目标。您可能想设置目标服务以发送通知,捕获状态信息,采取纠正措施,启动事件或采取其他操作。添加目标时,还必须向授予权限 EventBridge 以允许其调用所选目标服务。

每种类型的执行状态更改事件发出包含特定消息内容的通知,其中:

  • 初始 version 条目显示事件的版本号。

  • detail 管道下面的 version 条目显示管道结构版本号。

  • detail 管道下面的 execution-id 条目显示导致状态更改的管道执行的执行 ID。请参阅 “Amazon CodePipeline API参考” 中的GetPipelineExecutionAPI呼叫。

  • pipeline-execution-attempt 条目显示特定执行 ID 的尝试次数或重试次数。

CodePipeline EventBridge 每当您的资源状态发生 Amazon Web Services 账户 变化时,都会向其报告事件。对于以下资源,事件将在保证 at-least-once的基础上发出:

  • 管道执行

  • 阶段执行

  • 操作执行

事件由 EventBridge 触发,事件模式和架构详述如上所述。对于已处理的事件,例如通过在开发人员工具控制台中配置的通知收到的事件,事件消息包含的事件模式字段会有些变化。例如,detail-type 字段转换为 detailType。有关更多信息,请参阅 Amazon EventBridge API 参考中的PutEventsAPI电话会议

以下示例显示了的事件 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 为了响应RetryStageExecutionAPI调用,已重试失败的管道执行。
STARTED 当前正在运行管道执行。
STOPPED 停止过程已完成,管道执行已停止。
STOPPING 由于发出了停止并等待或停止并放弃管道执行的请求,管道执行正在停止。
SUCCEEDED 已成功完成管道执行。
SUPERSEDED

在该管道执行等待完成下一阶段时,启动了较新的管道执行并通过管道。

CodePipeline 阶段执行状态更改 CANCELED 已取消阶段,因为已更新管道结构。
FAILED 阶段未成功完成。
RESUMED 为了响应RetryStageExecutionAPI呼叫,已重试失败的阶段。
STARTED 当前正在运行阶段。
STOPPED 停止过程已完成,阶段执行已停止。
STOPPING 由于发出了停止并等待或停止并放弃管道执行的请求,阶段执行正在停止。
SUCCEEDED 已成功完成阶段。
CodePipeline 动作执行状态更改 ABANDONED 由于发出了停止并放弃管道执行的请求,已放弃操作。
CANCELED 已取消操作,因为已更新管道结构。
FAILED 对于批准操作,该FAILED状态表示该操作要么被审阅者拒绝,要么由于操作配置不正确而失败。
STARTED 当前正在运行操作。
SUCCEEDED 已成功完成操作。

管道级事件

当管道执行状态发生变化时,就会发出管道级事件。

管道STARTED事件

在启动管道执行时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-east-1 区域中名为 "myPipeline" 的管道。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事件

在停止管道执行时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-west-2 区域中名为 myPipeline 的管道。

{ "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事件

在管道执行成功时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-east-1 区域中名为 myPipeline 的管道。

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 标签的示例)

在管道执行有一个阶段已经重试并成功时,它发出一个事件以发送包含以下内容的通知。此示例适用于为 Git 标签配置了 execution-triggereu-central-1 区域中名为 myPipeline 的管道。

注意

execution-trigger 字段的值是 tag-namebranch-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事件

在管道执行失败时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-west-2 区域中名为 "myPipeline" 的管道。

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 标签的示例)

除非它在源阶段失败,否则对于配置了触发器的管道,它会发出一个事件,发送包含以下内容的通知。此示例适用于为 Git 标签配置了 execution-triggereu-central-1 区域中名为 myPipeline 的管道。

注意

execution-trigger 字段的值是 tag-namebranch-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活动

在启动阶段执行时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-east-1 区域中名为 "myPipeline" 的管道的 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活动

在停止阶段执行时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-west-2 区域中名为 myPipeline 的管道的 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活动

在阶段执行已停止时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-west-2 区域中名为 myPipeline 的管道的 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事件

在启动操作执行时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-east-1 区域中名为 myPipeline 的管道的部署操作 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事件

在操作执行成功时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-west-2 区域中名为 "myPipeline" 的管道的源操作 "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事件

在操作执行失败时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-west-2 区域中名为 "myPipeline" 的管道的 "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事件

在放弃操作执行时,它发出一个事件以发送包含以下内容的通知。此示例适用于 us-west-2 区域中名为 "myPipeline" 的管道的 "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 } }

创建发送管道事件通知的规则

规则监视某些事件,然后将其路由到您选择的 Amazon 目标。您可以创建在发生其他 Amazon 操作时自动执行 Amazon 操作的规则,也可以创建按设定的时间表定期执行 Amazon 操作的规则。

当管道状态发生更改时发送通知(控制台)

以下步骤说明如何使用 EventBridge 控制台创建规则,以发送更改通知 CodePipeline。

使用 Amazon S3 源创建针对您的管道的 EventBridge 规则
  1. 打开 Amazon EventBridge 控制台,网址为https://console.aws.amazon.com/events/

  2. 在导航窗格中,选择规则。保留选中的默认总线或选择一个事件总线。选择创建规则

  3. 名称中,输入规则的名称。

  4. 对于规则类型,选择具有事件模式的规则。选择下一步

  5. 事件模式下,选择 Amazon 服务

  6. 事件类型下拉列表中,选择通知的状态更改级别。

    • 要获取适用于管道级事件的规则,请选择CodePipeline管道执行状态更改。

    • 要获取适用于舞台级别事件的规则,请选择CodePipeline阶段执行状态更改

    • 要获取适用于操作级事件的规则,请选择CodePipeline操作执行状态更改

  7. 指定规则适用的状态更改:

    • 对于适用于所有状态更改的规则,请选择任意状态

    • 对于仅适用于某些状态更改的规则,请选择特定状态,然后从列表中选择一个或多个状态值。

  8. 对于比选择器允许的更详细的事件模式,也可以使用 “事件模式” 窗口中的 “编辑模式” 选项来指定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"] } }
  9. 选择下一步

  10. 目标类型中,选择 Amazon 服务

  11. 选择目标中,选择CodePipeline。在 Pi p elin ARN e 中ARN,输入要按此规则启动管道的管道。

    注意

    要获取管道ARN,请运行get-pipeline命令。管道ARN显示在输出中。它是使用以下格式构造的:

    arn: aws: 代码管道:region:account:pipeline-name

    示例管道ARN:

    arn: aws: codepipeline: us-east-2:80398: EXAMPLE MyFirstPipeline

  12. 要创建或指定IAM服务角色以授予调用与您的 EventBridge 规则关联的目标的 EventBridge 权限(在本例中,目标是 CodePipeline),请执行以下操作:

    • 选择 “为此特定资源创建新角色” 以创建服务角色,该角色 EventBridge 授予您启动管道执行的权限。

    • 选择 “使用现有角色” 输入一个服务角色,该角色 EventBridge 授予您启动管道执行的权限。

  13. 选择下一步

  14. 标签页面上,选择下一步

  15. 查看和创建页面上,检查规则配置。如果您对规则满意,请选择 Create rule

当管道状态发生变化时发送通知 (CLI)

以下步骤说明如何使用创建 CloudWatch 事件规则来发送更改通知 CodePipeline。CLI

要使用创建规则,请调用put-rule命令,指定: Amazon CLI

  • 唯一地标识创建的规则的名称。在您创建的与 Amazon 账户 CodePipeline 关联的所有管道中,此名称必须是唯一的。

  • 规则使用的源事件模式和详细信息字段。有关更多信息,请参阅 Amazon EventBridge 和事件模式

创建以事件源 CodePipeline 为对象的 EventBridge 规则
  1. 调用 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\"]}}"
  2. 调用 put-targets 命令并包含以下参数:

    • --rule 参数与您使用 put-rule 创建的 rule_name 结合使用。

    • --targets参数与目标列表Id中的目标列表和 Amazon SNS 主题ARN的列表一起使用。

    以下示例命令为名为 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
  3. EventBridge 添加使用指定目标服务调用通知的权限。有关更多信息,请参阅使用适用于 Amazon EventBridge 的基于资源的政策。