如果您正在从 AWS 负载中接收连续集成服务器(Jenkins、Travis 等)的负载,并且能够克隆存储库(如果要构建应用程序),则可以使用已安装的 git 工具获取消息。
这是来自 AWS 代码提交触发器到我的 CI 服务器的通知负载:
{
"Type": "Notification",
"MessageId": "296892a1a77b",
"TopicArn": "arn:aws:sns:us-bar-1:123456:TopicFoo",
"Subject": "UPDATE: AWS CodeCommit us-bar-1 push: my-awesome-repo",
"Message": ".....",
"Timestamp": "2021-06-23T20:57:15.040Z",
"SignatureVersion": "1",
"SigningCertURL": "https://sns.us-bar-1.amazonaws.com/SimpleNotificationService-foo-.pem",
"UnsubscribeURL": "https://foo.bar"
}
Message 字段被字符串化了 :s
{\"Records\":[{\"awsRegion\":\"us-bar-1\",\"codecommit\":{\"references\":[{\"commit\":\"fb28ebbec522cc403\",\"ref\":\"refs/heads/mybranch\"}]},\"customData\":null,\"eventId\":\"d1dab883\",\"eventName\":\"ReferenceChanges\",\"eventPartNumber\":1,\"eventSource\":\"aws:codecommit\",\"eventSourceARN\":\"arn:aws:codecommit:us-bar-1:123456:my-awesome-repo\",\"eventTime\":\"2021-06-23T20:57:15.005+0000\",\"eventTotalParts\":1,\"eventTriggerConfigId\":\"e4ea5f3bec6c\",\"eventTriggerName\":\"my_ci_server_notification\",\"eventVersion\":\"1.0\",\"userIdentityARN\":\"arn:aws:iam::123456:user/jane_doe\"}]}
但是如果我们将\"
替换为"
,就可以得到一个可读的JSON。
{
"Records": [{
"awsRegion": "us-bar-1",
"codecommit": {
"references": [{
"commit": "fb28ebbec522cc403",
"ref": "refs/heads/mybranch"
}]
},
"customData": null,
"eventId": "d1dab883",
"eventName": "ReferenceChanges",
"eventPartNumber": 1,
"eventSource": "aws:codecommit",
"eventSourceARN": "arn:aws:codecommit:us-bar-1:123456:my-awesome-repo",
"eventTime": "2021-06-23T20:57:15.005+0000",
"eventTotalParts": 1,
"eventTriggerConfigId": "e4ea5f3bec6c",
"eventTriggerName": "my_ci_server_notification",
"eventVersion": "1.0",
"userIdentityARN": "arn:aws:iam::123456:user/jane_doe"
}]
}
"references": [{
"commit": "fb28ebbec522cc403",
"ref": "refs/heads/mybranch"
}]
git log --format=%B -n 1 fb28ebbec522cc403