AWS Cloudwatch 在动态标签上触发 Codepipeline

AWS Cloudwatch trigger Codepipeline on dynamic tag

我想用动态标签标记提交,例如 git tag deploy-$(date +"%Y-%m-%d_%H-%M-%S"),然后从 cloudwatch 触发代码管道。问题是如果我使用以下 cloudwatch 事件模式:

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit Repository State Change"
  ],
  "resources": [
    "arn:aws:codecommit:region:XXX:someName"
  ],
  "detail": {
    "event": [
      "referenceCreated",
      "referenceUpdated"
    ],
    "repositoryName": [
      "someName"
    ],
    "referenceType": [
      "tag"
    ],
    "referenceName": [
      "deploy"
    ]
  }
}

它只会在特定标签 - “部署”上触发。有没有办法说出任何以(包含)部署关键字开头的标签?

您可以在前缀中使用通配符:

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit Repository State Change"
  ],
  "detail": {
    "referenceType": [
      "tag"
    ],
    "referenceName": [
      {
        "prefix": "deploy-*"
      }
    ]
  }
}

我在看 Content-based Filtering with Event Patterns docs and its Prefix Matching。文档中给出的示例是:

{
  "time": [ { "prefix": "2017-10-02" } ],
}

根据示例,以下内容似乎适用于您的情况:

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit Repository State Change"
  ],
  "resources": [
    "arn:aws:codecommit:region:XXX:someName"
  ],
  "detail": {
    "event": [
      "referenceCreated",
      "referenceUpdated"
    ],
    "repositoryName": [
      "someName"
    ],
    "referenceType": [
      "tag"
    ],
    "referenceName": [
       { "prefix": "deploy" } ]
    ]
  }
}