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