繁体   English   中英

在GitLab CI构建期间如何从私有GitLab Git存储库中提取NPM依赖关系

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM