繁体   English   中英

从 Github 镜像到 AWS CodeCommit 时出错

[英]Error while mirroring from Github to AWS CodeCommit

我在eu-central-1创建了一个 AWS CodeCommit 存储库。 我计划将 GitHub 中的存储库同步到 AWS CodeCommit。 所有当前代码和未来 PR 合并到 main 和 preprod 都应该在 AWS CodeCommit 中。 我正在使用此脚本在我的 Jenkins 阶段从 GitHub 动作编写脚本

git config --global credential.'https://git-codecommit.*.amazonaws.com'.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
git remote add sync https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/test-repo
git push sync --mirror

我收到以下错误

fatal: could not read Username for 'https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/test-repo': No such device or address

Jenkins 作业正在运行的作业具有附加到实例的角色,并且它对 CodeCommit 具有完全权限。 在镜像解决上述问题之前,我是否缺少任何先决条件或必须执行任何先决条件?

注意/免责声明:我没有研究(或测试,就此而言)被引用的特定 GitHub 操作,但仅提供有关如何确保您可以将“主要” Git 存储库与“辅助”存储库同步的说明" Git 存储库使用 EC2 实例托管在 AWS CodeCommit 上。

使用 EC2 实例(例如托管 Jenkins)时,您应该首先验证它是否附加了 IAM 角色,并且该 IAM 角色附加了必要的 IAM 策略以读取/写入 CodeCommmit(例如 AWSCodeCommitPowerUser)。

如果是这种情况,您接下来应该测试 EC2 实例是否可以查询 CodeCommit 存储库,例如通过执行以下命令(当然是替换):

aws codecommit get-repository --repository-name <REPO-NAME> --region <REGION>

如果此操作成功,您就可以为 CodeCommit 设置 Git 凭证,以便 Git CLI 可以使用它。 这是通过问题中已经提供的git [..] credential命令完成的,也可以在CodeCommit 的官方 AWS 文档中找到

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

接下来,检查 Git 是否可以直接与 CodeCommit 对话(即不使用 AWS CLI),例如通过克隆存储库:

git clone https://git-codecommit.<REGION>.amazonaws.com/v1/repos/<REPO-NAME>

现在您应该对 go 很好,以同步来自主存储库的更改。 因此,在克隆主存储库后, cd进入它,然后运行命令将 CodeCommit 存储库设置为远程,然后推送副本。

git remote add sync https://git-codecommit.<REGION>.amazonaws.com/v1/repos/<REPO-NAME>
git push sync --mirror

这应该已成功确认,更改现在将在 CodeCommit 存储库中可见。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM