0

I am setting up aws code pipeline based on the git developer branch. when the developer commits his code, the pipeline will be trigger based on the webhook. Now the idea is when there is a failure in the pipeline, and when the developer triggers a pull-request, the reviewer should know that this is bad branch. He should be able to see the git status of the branch showing there is a failure.

Earlier I have used a build tool called Codeship which has a git-hub app to do this stuff. Now I have gone through git-hub API https://developer.github.com/v3/checks/runs/#create-a-check-run But not sure where to start.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
AJ2385
  • 1
  • 3
  • Did you consider tagging the branch? And perhaps it is better to prevent the creation of the pull request at all if the branch is failing the build. See also: https://aws.amazon.com/blogs/devops/validating-aws-codecommit-pull-requests-with-aws-codebuild-and-aws-lambda/ – Emond Oct 25 '19 at 10:51

2 Answers2

0

To send a notification when stage fails, please follow these steps:

  1. Based on your Cloudwatch events emitted by CodePipeline [0], trigger a lambda function [1].

  2. Lambda function can trigger API call "list-pipeline-executions"[2] and from that you can fetch all the required values like Commit Id, status message etc [3].

  3. Once the values are fetched, you can send same value to SNS by writing lambda function code inside same lambda. Following blogs shows how to publish in SNS using lambda [4][5].

[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] Can you publish a message to an SNS topic using an AWS Lambda function backed by node.js?

shariqmaws
  • 8,152
  • 1
  • 16
  • 35
0

I have done the following to write back the status to gitrepo:

I have made use of gitstatus api: https://developer.github.com/v3/repos/statuses/ Written a Lambda function to do POST request with these details state, TargetURL , context

{ "state": "success", "target_url": "https://example.com/build/status" (Build Tool URL like codebuild or jenkins) "description": "The build succeeded!", "context": "continuous-integration/jenkins" }

the response here should be "url": "https://api.github.com/repos//-/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e ",

All these details can be obtained using CLoudwatch event for the pipeline. by using patterns of event detail list : event.detail.state;event.detail.pipeline;event.region, event ['detail']['execution-id'], data.pipelineExecution.artifactRevisions[0].revisionUrl

Cheers.

AJ2385
  • 1
  • 3