有没有一种方法可以使用AWS CodePipeline根据Git标签的存在从GitHub有条件地部署



特别是,我希望能够在GitHub中用某种模式(例如"^v[0-9].*"(标记一个版本,并触发AWS CodePipeline。

提前谢谢。

-标记

您可以在Github中使用apigateway和lambda创建一个webhook,并有条件地从lambda触发管道。

您需要首先创建一个lambda函数,然后创建一个指向该lambda的api网关端点(POST(。然后转到Github>lt;Your_Project>gt;设置>Webhook,并使用api网关url创建一个Webhook。然后,您将在lambda函数的事件参数中获得所有事件的post有效载荷,您可以解析该有效载荷以获得版本或标记的详细信息,并使用boto3(python(从lambda启动管道。

github:的样本有效载荷

{'action': 'created', 'release': {'url': 'https://api.github.com/repos/NiminU/webhooktest/releases/33092173', 'assets_url': 'https://api.github.com/repos/NiminU/webhooktest/releases/33092173/assets', 'upload_url': 'https://uploads.github.com/repos/NiminU/webhooktest/releases/33092173/assets{?name,label}', 'html_url': 'https://github.com/NiminU/webhooktest/releases/tag/v1.0', 'id': 33092173, 'node_id': 'MDc6UmVsZWFzZTMzMDkyMTcz', 'tag_name': 'v1.0', 'target_commitish': 'main', 'name': 'v1.0', 'draft': False, 'author': {'login': 'NiminU', 'id': 47168398, 'node_id': 'MDQ6VXNlcjQ3MTY4Mzk4', 'avatar_url': 'https://avatars1.githubusercontent.com/u/47168398?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/NiminU', 'html_url': 'https://github.com/NiminU', 'followers_url': 'https://api.github.com/users/NiminU/followers', 'following_url': 'https://api.github.com/users/NiminU/following{/other_user}', 'gists_url': 'https://api.github.com/users/NiminU/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/NiminU/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/NiminU/subscriptions', 'organizations_url': 'https://api.github.com/users/NiminU/orgs', 'repos_url': 'https://api.github.com/users/NiminU/repos', 'events_url': 'https://api.github.com/users/NiminU/events{/privacy}', 'received_events_url': 'https://api.github.com/users/NiminU/received_events', 'type': 'User', 'site_admin': False}, 'prerelease': False, 'created_at': '2020-10-27T05:58:22Z', 'published_at': '2020-10-27T06:14:34Z', 'assets': [], 'tarball_url': 'https://api.github.com/repos/NiminU/webhooktest/tarball/v1.0', 'zipball_url': 'https://api.github.com/repos/NiminU/webhooktest/zipball/v1.0', 'body': 'This is the first release'}, 'repository': {'id': 307599246, 'node_id': 'MDEwOlJlcG9zaXRvcnkzMDc1OTkyNDY=', 'name': 'webhooktest', 'full_name': 'NiminU/webhooktest', 'private': True, 'owner': {'login': 'NiminU', 'id': 47168398, 'node_id': 'MDQ6VXNlcjQ3MTY4Mzk4', 'avatar_url': 'https://avatars1.githubusercontent.com/u/47168398?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/NiminU', 'html_url': 'https://github.com/NiminU', 'followers_url': 'https://api.github.com/users/NiminU/followers', 'following_url': 'https://api.github.com/users/NiminU/following{/other_user}', 'gists_url': 'https://api.github.com/users/NiminU/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/NiminU/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/NiminU/subscriptions', 'organizations_url': 'https://api.github.com/users/NiminU/orgs', 'repos_url': 'https://api.github.com/users/NiminU/repos', 'events_url': 'https://api.github.com/users/NiminU/events{/privacy}', 'received_events_url': 'https://api.github.com/users/NiminU/received_events', 'type': 'User', 'site_admin': False}, 'html_url': 'https://github.com/NiminU/webhooktest', 'description': None, 'fork': False, 'url': 'https://api.github.com/repos/NiminU/webhooktest', 'forks_url': 'https://api.github.com/repos/NiminU/webhooktest/forks', 'keys_url': 'https://api.github.com/repos/NiminU/webhooktest/keys{/key_id}', 'collaborators_url': 'https://api.github.com/repos/NiminU/webhooktest/collaborators{/collaborator}', 'teams_url': 'https://api.github.com/repos/NiminU/webhooktest/teams', 'hooks_url': 'https://api.github.com/repos/NiminU/webhooktest/hooks', 'issue_events_url': 'https://api.github.com/repos/NiminU/webhooktest/issues/events{/number}', 'events_url': 'https://api.github.com/repos/NiminU/webhooktest/events', 'assignees_url': 'https://api.github.com/repos/NiminU/webhooktest/assignees{/user}', 'branches_url': 'https://api.github.com/repos/NiminU/webhooktest/branches{/branch}', 'tags_url': 'https://api.github.com/repos/NiminU/webhooktest/tags', 'blobs_url': 'https://api.github.com/repos/NiminU/webhooktest/git/blobs{/sha}', 'git_tags_url': 'https://api.github.com/repos/NiminU/webhooktest/git/tags{/sha}', 'git_refs_url': 'https://api.github.com/repos/NiminU/webhooktest/git/refs{/sha}', 'trees_url': 'https://api.github.com/repos/NiminU/webhooktest/git/trees{/sha}', 'statuses_url': 'https://api.github.com/repos/NiminU/webhooktest/statuses/{sha}', 'languages_url': 'https://api.github.com/repos/NiminU/webhooktest/languages', 'stargazers_url': 'https://api.github.com/repos/NiminU/webhooktest/stargazers', 'contributors_url': 'https://api.github.com/repos/NiminU/webhooktest/contributors', 'subscribers_url': 'https://api.github.com/repos/NiminU/webhooktest/subscribers', 'subscription_url': 'https://api.github.com/repos/NiminU/webhooktest/subscription', 'commits_url': 'https://api.github.com/repos/NiminU/webhooktest/commits{/sha}', 'git_commits_url': 'https://api.github.com/repos/NiminU/webhooktest/git/commits{/sha}', 'comments_url': 'https://api.github.com/repos/NiminU/webhooktest/comments{/number}', 'issue_comment_url': 'https://api.github.com/repos/NiminU/webhooktest/issues/comments{/number}', 'contents_url': 'https://api.github.com/repos/NiminU/webhooktest/contents/{+path}', 'compare_url': 'https://api.github.com/repos/NiminU/webhooktest/compare/{base}...{head}', 'merges_url': 'https://api.github.com/repos/NiminU/webhooktest/merges', 'archive_url': 'https://api.github.com/repos/NiminU/webhooktest/{archive_format}{/ref}', 'downloads_url': 'https://api.github.com/repos/NiminU/webhooktest/downloads', 'issues_url': 'https://api.github.com/repos/NiminU/webhooktest/issues{/number}', 'pulls_url': 'https://api.github.com/repos/NiminU/webhooktest/pulls{/number}', 'milestones_url': 'https://api.github.com/repos/NiminU/webhooktest/milestones{/number}', 'notifications_url': 'https://api.github.com/repos/NiminU/webhooktest/notifications{?since,all,participating}', 'labels_url': 'https://api.github.com/repos/NiminU/webhooktest/labels{/name}', 'releases_url': 'https://api.github.com/repos/NiminU/webhooktest/releases{/id}', 'deployments_url': 'https://api.github.com/repos/NiminU/webhooktest/deployments', 'created_at': '2020-10-27T05:57:32Z', 'updated_at': '2020-10-27T05:58:25Z', 'pushed_at': '2020-10-27T06:14:34Z', 'git_url': 'git://github.com/NiminU/webhooktest.git', 'ssh_url': 'git@github.com:NiminU/webhooktest.git', 'clone_url': 'https://github.com/NiminU/webhooktest.git', 'svn_url': 'https://github.com/NiminU/webhooktest', 'homepage': None, 'size': 0, 'stargazers_count': 0, 'watchers_count': 0, 'language': None, 'has_issues': True, 'has_projects': True, 'has_downloads': True, 'has_wiki': True, 'has_pages': False, 'forks_count': 0, 'mirror_url': None, 'archived': False, 'disabled': False, 'open_issues_count': 0, 'license': None, 'forks': 0, 'open_issues': 0, 'watchers': 0, 'default_branch': 'main'}, 'sender': {'login': 'NiminU', 'id': 47168398, 'node_id': 'MDQ6VXNlcjQ3MTY4Mzk4', 'avatar_url': 'https://avatars1.githubusercontent.com/u/47168398?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/NiminU', 'html_url': 'https://github.com/NiminU', 'followers_url': 'https://api.github.com/users/NiminU/followers', 'following_url': 'https://api.github.com/users/NiminU/following{/other_user}', 'gists_url': 'https://api.github.com/users/NiminU/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/NiminU/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/NiminU/subscriptions', 'organizations_url': 'https://api.github.com/users/NiminU/orgs', 'repos_url': 'https://api.github.com/users/NiminU/repos', 'events_url': 'https://api.github.com/users/NiminU/events{/privacy}', 'received_events_url': 'https://api.github.com/users/NiminU/received_events', 'type': 'User', 'site_admin': False}}`

您可以在这里使用有效负载中的tag_name密钥来进行逻辑

代码管道boto3文档:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codepipeline.html

相关内容

  • 没有找到相关文章

最新更新