在GitLab CI构建期间如何从私有GitLab Git存储库中提取NPM依赖关系 [英] How to pull NPM dependency from private GitLab Git repo during GitLab CI build
问题描述
我的.gitlab-ci.yml
文件中有一个工作,它像这样执行npm install
:
I have a job in my .gitlab-ci.yml
file which does an npm install
like so:
test:
image: node:10
script:
- npm install
- npm test
问题是我在package.json
中引用了私有的GitLab存储库:
The problem is that I'm referencing a private GitLab repo in my package.json
:
"dependencies": {
"internal-dep": "git+https://gitlab.com/Company/internal-dep.git",
...
npm install
命令在本地工作,因为我已经针对GitLab进行了身份验证,但是在GitLab CI上失败.如何获得internal-dep
在GitLab CI上成功解决的问题?
The npm install
command works locally, since I'm already authed against GitLab, but fails on GitLab CI. How do I get internal-dep
to resolve successfully on GitLab CI?
推荐答案
我发现了两种方法,这些方法允许Git在npm install
步骤中成功对GitLab进行身份验证(该方法在后台使用Git来访问此依赖项) ).
There are two approaches I've found that allow Git to auth successfully against GitLab during the npm install
step (which uses Git under the hood to access this dependency).
第一种方法,如此.gitlab-ci.yml
作业所示:
First approach, as shown in this .gitlab-ci.yml
job:
test:
image: node:10
script:
- echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
- npm install
- npm test
第二种方法似乎也可行:
Second approach, which also seems to work:
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
这篇关于在GitLab CI构建期间如何从私有GitLab Git存储库中提取NPM依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!