且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-12-12 19:53:39

我发现有两种方法可以让 Git 在 npm install 步骤(在访问此依赖项的引擎盖).

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
login gitlab-ci-token
password ${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