github - 如果 repo 是组织存储库,AWS CodePipeline GitHub webhook 无法注册到 GitHub
问题描述
当我使用控制台设置挂钩时,它可以工作,但是当我尝试使用 cloudformation 进行设置时,它永远不会工作。如果我使用 AWS CLI 版本,它甚至都不起作用:
aws codepipeline register-webhook-with-third-party --webhook-name AppPipelineWebhook-aOnbonyFrNZu
这就是我的 webhook 的样子(“aws codepipeline list-webhooks”的输出):
{
"webhooks": [
{
"definition": {
"name": "AppPipelineWebhook-aOnbonyFrNZu",
"targetPipeline": "ftp-proxy-cf",
"targetAction": "GitHubAction",
"filters": [
{
"jsonPath": "$.ref",
"matchEquals": "refs/heads/{Branch}"
}
],
"authentication": "GITHUB_HMAC",
"authenticationConfiguration": {
"SecretToken": "<REDACTED>"
}
},
"url": "https://eu-west-1.webhooks.aws/trigger?t=eyJ<ALSO REDACTED>F9&v=1",
"arn": "arn:aws:codepipeline:eu-west-1:<our account ID>:webhook:AppPipelineWebhook-aOnbonyFrNZu",
"tags": []
}
]
}
我得到的错误是:
An error occurred (ValidationException) when calling the RegisterWebhookWithThirdParty operation: Webhook could not be registered with GitHub. Error cause: Not found [StatusCode: 404, Body: {"message":"Not Found","documentation_url":"https://developer.github.com/v3/repos/hooks/#create-a-hook"}]
这些是我的 cloudformation 文件中的两个相关部分:
Resources:
AppPipelineWebhook:
Type: AWS::CodePipeline::Webhook
Properties:
Authentication: GITHUB_HMAC
AuthenticationConfiguration:
SecretToken: '{{resolve:secretsmanager:my/secretpath/github:SecretString:token}}'
Filters:
- JsonPath: $.ref
MatchEquals: 'refs/heads/{Branch}'
TargetPipeline: !Ref CodePipeline
TargetAction: GitHubAction
TargetPipelineVersion: !GetAtt CodePipeline.Version
# RegisterWithThirdParty: true
CodePipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name:
Ref: PipelineName
RoleArn: !GetAtt CodePipelineServiceRole.Arn
Stages:
- Name: Source
Actions:
- Name: GitHubAction
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: 1
Provider: GitHub
OutputArtifacts:
- Name: SourceOutput
Configuration:
Owner: myorganisationnameongithub
Repo: ftp-proxy
Branch: master
OAuthToken: '{{resolve:secretsmanager:my/secretpath/github:SecretString:token}}'
PollForSourceChanges: false
它可以轮询变化。因此,如果我从 AWS 控制台手动命令执行 GitHubAction 阶段,则会下载最新的提交。如果我设置PollForSourceChanges: true
,这种轮询也可以,但是 webhook 工作流不行(因为钩子不能在 GitHub 上注册)
解决方案
由于 (2) 可能的原因,观察到错误:
个人访问令牌 (PAT) 未配置为具有以下 GitHub 范围:admin:repo_hook 和 admin:org_hook 1
您可以在“用户”(右上角)>“设置”>“开发者设置”>“个人访问令牌”下验证这些权限
CloudFormation 模板中的“所有者”和/或“存储库”名称不正确:
对于 CloudFormation 中的管道配置,请确保“GitHubOwner”是“组织名称”并且存储库名称只是存储库名称并且其中没有“org/repo_name”,例如在您的情况下:
Configuration:
Owner: !Ref GitHubOwner <========== Github org name
Repo: !Ref RepositoryName
Branch: !Ref BranchName
OAuthToken: !Ref GitHubOAuthToken <========== <Personal Access Token>
推荐阅读
- django - Django - UserManager(BaseUserManager) - 问题 - 为什么电子邮件和用户名不会打印到终端?
- python - 在 Python 的用户函数中同时传递多个数据帧作为参数
- java - 数组中 N 个元素的绝对差的最大和
- presto - Presto 查询以根据特定列中的值排除行
- r - 如何使用 R 运行具有大而稀疏数据矩阵的验证性因子分析模型?
- sql - 如何进行循环 SUM() 金额?
- batch-file - 如何获取使用 PSEXEC 命令启动的批处理的返回码?
- excel - 如何隐式调用类的默认函数
- jquery - 如何将 HTML AJAX 响应保存在 var 中?
- c# - 使用 Microsoft.AspNetCore.ApiAuthorization.IdentityServer 时如何在 JWT 和用户主体中添加自定义用户声明