我正在开发一个前端应用程序,该应用程序依赖于我们组织开发的依赖项,但托管在单独的存储库中。这是一个由我们托管的 bitbucket 存储库,是私有(private)的。
我们使用 NPM 来管理这个依赖项,并通过 git+https://<the-dependency-repo>.com
安装它
这在我们的本地环境中有效,因为我们的凭据已缓存。请注意:我们无法切换到 SSH。我知道 ssh 解决方案,我无法控制帐户管理、bitbucket 访问等...
当 Jenkins CI 运行时,它使用存储在凭证插件中的凭证从它的存储库中提取我们的应用程序,并运行 npm install
.
问题:
由于在 npm install
期间身份验证失败,安装失败.
到目前为止我尝试了什么:
由于 git 凭据存储在 Jenkins 凭据插件中,我可以访问 git 用户名/密码组合。
确切的失败发生在 npm 尝试运行 git ls-remote ...
时
为了避免这种身份验证失败,我可以在 npm 安装之前运行一个 shell 命令:
git config credential.helper 'cache'
git fetch https://${USERPASSCOMBO}@<repo>
好消息是这有效! NPM 能够运行 git fetch ls-remote
没有错误
坏消息是下一个命令git clone -q <repo>
失败。
我尝试了相同的解决方案:在 npm install 之前添加以下内容:
git config credential.helper 'cache'
git ls-remote https://${USERPASSCOMBO}@<repo>
git clone https://${USERPASSCOMBO}@<repo>
注意:这些命令在 npm 安装之前按预期工作
NPM 安装仍然失败,产生以下错误输出:
[ERROR] npm ERR! Command failed: /bin/git clone -q https://<repo> /var/lib/jenkins/.npm/_cacache/tmp/git-clone-ed5ac1a9
[ERROR] npm ERR! warning: templates not found /tmp/pacote-git-template-tmp/git-clone-49feabe4
[ERROR] npm ERR! fatal: Authentication failed for '<repo>'
[ERROR] npm ERR!
非常感谢任何帮助,即使是指向正确方向的指针。我已经用尽了所有我能想到的方法。
最佳答案
尝试使用 URL git+https://user:password@<repo-url>
从存储库安装.
请注意,这会将您的密码公开,因此如果您的存储库提供商支持,我建议生成应用 token 或类似 token 。
关于node.js - jenkins build 上私有(private) repo 的 NPM 身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49885383/