[英]How to pull NPM dependency from private GitLab Git repo during GitLab CI build
我的.gitlab-ci.yml
文件中有一份工作, .gitlab-ci.yml
文件执行npm install
如下所示:
test:
image: node:10
script:
- npm install
- npm test
问题是我在package.json
引用了私有的GitLab存储库:
"dependencies": {
"internal-dep": "git+https://gitlab.com/Company/internal-dep.git",
...
npm install
命令在本地工作,因为我已经针对GitLab进行了身份验证,但是在GitLab CI上失败。 如何在GitLab CI上成功解决internal-dep
问题?
我发现有两种方法可以使Git在npm install
步骤中成功地针对GitLab进行身份验证(该方法在npm install
使用Git访问此依赖项)。
第一种方法,如此.gitlab-ci.yml
作业所示:
test:
image: node:10
script:
- echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
- npm install
- npm test
第二种方法似乎也可行:
test:
image: node:10
script:
- git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf https://gitlab.com/
- npm install
- npm test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.