amazon-web-services - 尝试从私有 Codecommit 存储库中提取时,在 CodeBuild 上安装 NPM 失败
问题描述
我在 codecommit 中的一个 repo 正在尝试从我的另一个 codecommit repos 中提取。
在第一个 repo 的 package.json 中有依赖项:
"dependencies": {
"repo-2": "git+https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/repo-2.git#TAG"
}
我的代码构建在尝试时抛出错误npm install
(代码构建正在使用 nodejs12):
npm ERR! Command failed: git clone --mirror -q https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/repo-2.git
/root/.npm/_cacache/tmp/git-clone-3d2bf4b6/.git
npm ERR! warning: templates not found in /tmp/pacote-git-template-tmp/git-clone-7cae5b66
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-01-26T11_58_45_260Z-debug.log
我已确保在我的策略中提供正确的权限:
- Sid: CodeCommitRepoAccess
Effect: Allow
Action:
- codecommit:GetRepository
- codecommit:GitPull
- codecommit:GetFolder
Resource:
- arn:aws:codecommit:eu-west-1:*
- Sid: CodeCommitListRepos
Effect: Allow
Action:
- codecommit:ListRepositories
Resource: "*"
我在 buildspec.yaml 中添加了 git-credential 助手:
env:
git-credential-helper: yes
我真的不知道为什么会失败,而且错误消息并没有让我知道需要修复什么。也许我错过了策略中的一些权限?- 但由于它不是 403 错误,我不确定。我可以npm install
在我的机器上本地没有任何问题。
编辑:实际上更清楚地说,我正在尝试从 repo-1 构建,它依赖于 repo-2 和 repo-3。此外,repo-2 也依赖于 repo-3。我尝试在npm install
没有嵌套私有存储库的情况下运行(作为测试将其从 package.json 中删除),但构建仍然以同样的方式失败。
更新:我将这一行添加git ls-remote -h -t https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/repo-2.git
到我的构建规范中,这会正确返回 repo-2 中的分支/标签,因此权限看起来不错。
解决方案
如果有人有同样的问题,请回答:
在安装阶段将以下内容添加到我的构建规范中解决了该问题:
- git config --global credential.helper '!aws codecommit credential-helper $@'
- git config --global credential.UseHttpPath true
我还需要从我的构建规范中删除git-credential 助手:
env:
git-credential-helper: yes
我认为导致问题的原因是,npm install
当它使用 env 设置时,它没有拾取 git-credential 助手,但在明确设置时确实被拾取。
推荐阅读
- apache - Drupal 7 .htaccess 文件不强制重定向到 HTTPS
- python - PySide/PyQt:在 GUI 加载后执行函数
- javascript - jQuery更改事件顺序
- vba - 基于前一个单元格中的数据的 Excel VBA 前导零
- maven - 帮助 Ivy 知道两个组织不同的工件是相同的
- javascript - 使用 lodash 方法返回新形式的数组
- dictionary - 如何在 Java 8 中使用方法引用进行 Map 合并?
- ruby - 使用 Logstash 和 Ruby 提取嵌套对象
- asp.net - ASP.NET MVC 5 掩码下载链接到 Amazon S3 资源
- php - Laravel 自定义异常