【问题标题】:My CloudWatch Event rule doesn't trigger my CodePipeline pipeline我的 CloudWatch 事件规则不会触发我的 CodePipeline 管道
【发布时间】:2019-04-22 02:15:02
【问题描述】:

我在使用 AWS CloudWatch Events 时遇到了一些问题。

我正在创建一个 CodePipeline CI 管道,其中有一个 CodeCommit 存储库作为源,一个 CodeBuild 项目作为构建/测试阶段(然后,它部署到 Lambda,但问题不存在)。

我们有多个项目,我们将推动多个其他项目。因此,我创建了一个脚本来管理 AWS CI 内容(即创建一个管道、一个 CodeBuild 项目……以及一个与管道链接的 CloudWatch Events 规则)。

我第一次推送我的代码时,它可以工作。但是,该过程停止被 CodeCommit 上的推送触发。

我找到了一个解决方案(但不是我想要的那个):我只需要修改管道,修改阶段(源),不触及任何东西,并保存空修改:它可以工作(在保存之前,它会询问创建与此管道关联的 CloudWatch Events 规则的授权)。

有人遇到过这个问题吗?你做了什么绕过它? 我真的很想制作一个 100% 自动化的 CI,我不想每次我的团队创建新存储库或在现有存储库上推送新分支时都去 AWS 控制台。

编辑:

这是我的 CloudWatch Events 规则的 JSON:

{
    "Name": "company-ci_codepipeline_project-stage", 
    "EventPattern": "cf. second JSON", 
    "State": "ENABLED", 
    "Arn": "arn:aws:events:region:xxx:rule/company-ci_codepipeline_project-stage", 
    "Description": "CloudWatch Events rule to automatically trigger the needed pipeline from every push to project repository, on the stage branch on CodeCommit."
}

这是EventPattern JSON:

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit repository state change"
  ],
  "resources": [
    "arn:aws:codecommit:region:xxx:project"
  ],
  "detail": {
    "event": [
      "referenceCreated",
      "referenceUpdated"
    ],
    "referenceType": [
      "branch"
    ],
    "referenceName": [
      "stage"
    ]
  }
}

【问题讨论】:

  • 您的 CloudWatch 事件规则是什么?您是否看到规则的 CloudWatch 指标显示您推送时触发的规则?我正在尝试找出问题出在规则还是管道上。
  • @TimB,我的 CloudWatch Events 规则有一个带有 CodeCommit 源的模板,以及每次 与名为 devbranch 匹配的详细信息>createdupdated(使用良好的 JSON 格式)。我看不到我的规则的任何指标!
  • 你能发布规则的实际 JSON 吗?
  • @TimB,我用所需的 JSON 更新了我的帖子

标签: amazon-web-services continuous-integration amazon-cloudwatch aws-codepipeline


【解决方案1】:

我发现此问题通常与事件规则/目标/角色配置有关。如果您没有与规则关联的目标,则在查看指标时将不会看到调用的事件。由于您的 EventPattern 看起来正确,我认为目标可能是您的问题。

你应该有一个看起来像这样的配置目标:

{
    "Rule": "company-ci_codepipeline_project-stage",
    "Targets": [
        {
            "RoleArn": "arn:aws:iam::xxx:role/cwe-codepipeline",
            "Id": "ProjectPipelineTarget",
            "Arn": "arn:aws:codepipeline:region:xxx:your-pipeline"
        }
    ]
}

如果看起来一切正常,接下来我会检查与目标关联的角色是否授予了正确的权限。我的角色类似于:

{
    "Role": {
        "Description": "Allows CloudWatch Events to invoke targets and perform actions in built-in targets on your behalf.",
        "AssumeRolePolicyDocument": {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Action": "sts:AssumeRole",
                    "Principal": {
                        "Service": "events.amazonaws.com"
                    },
                    "Effect": "Allow",
                    "Sid": ""
                }
            ]
        },
        "MaxSessionDuration": 3600,
        "RoleId": "xxxx",
        "CreateDate": "2018-08-06T20:56:19Z",
        "RoleName": "cwe-codepipeline",
        "Path": "/",
        "Arn": "arn:aws:iam::xxx:role/cwe-codepipeline"
    }
}

它有一个内联策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codepipeline:StartPipelineExecution"
            ],
            "Resource": [
                "arn:aws:codepipeline:*:xxx:*"
            ]
        }
    ]
}

作为参考,请查看此documentation

【讨论】:

    猜你喜欢
    • 2019-07-15
    • 2020-09-20
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 2021-09-12
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多