Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull NPM dependency from private GitLab Git repo during GitLab CI build

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

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",
  ...

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?

like image 841
Matt Vukas Avatar asked Feb 04 '23 21:02

Matt Vukas


1 Answers

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).

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
like image 129
Matt Vukas Avatar answered Feb 07 '23 10:02

Matt Vukas