我有一份 Jenkins 工作来构建我的 JS 应用程序。
在我的 package.json
我有一个看起来像这样的依赖项:
"devDependencies": {
"my_private_package": "git+https://my-server/my-repo.git#1.0.0"
}
我使用 Jenkins Git Plugin随着Credentials Plugin克隆 repo,然后运行 shell 脚本
npm install
.当 Jenkins 运行时
npm install
, npm
npm ERR! fatal: Authentication failed
出错由于我们自托管的 git 服务器和官僚作风,我无法通过向 git url 添加 oAuth token 做任何事情。
有没有办法让我设置我的 git 凭据,以便 npm 可以从我的受密码保护的 git repo 安装?
最佳答案
您可以使用 credential-helper 向 git 提供 HTTPS 凭据。用文件配置。 file format只是一个带有 user:password
的 HTTPS URL凭据部分已填写。类似于:
CREDENTIALS_FILE_PATH="$HOME/.git/my-ci-credentials"
cat 'https://ci-user:ci-password@myRepoHost.example.com/' > "$CREDENTIALS_FILE_PATH"
因为 npm 在项目文件夹的上下文之外克隆 repo,所以您需要在用户级别而不是项目级别指定此配置:git config --global credential.helper "store --file=$CREDENTIALS_FILE_PATH"
在此之后,npm 应该能够克隆 repo。
关于当 npm 具有 git 依赖项时的 Git 凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43762237/