当 aws codepipeline 出现故障时,有没有办法将 git 检查状态写回 git

Is there a way to write git check status back to git when there is a failure in awscode pipeline

我正在根据 git 开发人员分支设置 aws 代码管道。 当开发人员提交他的代码时,管道将基于 webhook 被触发。现在的想法是,当管道出现故障时,当开发人员触发拉取请求时,审阅者应该知道这是错误的分支。他应该能够看到显示失败的分支的 git 状态。

早些时候我使用了一个名为 Codeship 的构建工具,它有一个 git-hub 应用程序来做这些事情。现在我已经通过 git-hub API https://developer.github.com/v3/checks/runs/#create-a-check-run 但不知道从哪里开始。

要在阶段失败时发送通知,请按照以下步骤操作:

  1. 根据 CodePipeline [0] 发出的 Cloudwatch 事件,触发 lambda 函数 [1]。

  2. Lambda 函数可以触发 API 调用 "list-pipeline-executions"[2],您可以从中获取所有必需的值,例如提交 ID、状态消息等 [3]。

  3. 获取值后,您可以通过在同一个 lambda 中编写 lambda 函数代码,将相同的值发送到 SNS。以下博客展示了如何使用 lambda [4][5].

  4. 在 SNS 中发布

[0] https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-cloudwatch-sns-notifications.html

[1] https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html

[2] https://docs.aws.amazon.com/cli/latest/reference/codepipeline/list-pipeline-executions.html

[3] https://docs.aws.amazon.com/cli/latest/reference/codepipeline/index.html

[4]https://gist.github.com/jeremypruitt/ab70d78b815eae84e037

[5]

我已经完成以下操作将状态写回 gitrepo:

我使用了 gitstatus api: https://developer.github.com/v3/repos/statuses/ 使用这些详细信息编写了一个 Lambda 函数来执行 POST 请求 状态,目标URL,上下文

{ "state": "success", "target_url":“https://example.com/build/status”(构建工具 URL,如 codebuild 或 jenkins) "description": "The build succeeded!", "context": "continuous-integration/jenkins" }

这里的响应应该是 "url": "https://api.github.com/repos//-/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",

可以使用管道的 CLoudwatch 事件获取所有这些详细信息。通过使用事件详细信息列表的模式: event.detail.state;event.detail.pipeline;event.region, 事件 ['detail']['execution-id'], data.pipelineExecution.artifactRevisions[0].revisionUrl

干杯。