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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With