簡體   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