Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install private npm package in gitlab pipelines

If one needs to install private repositories with npm the environment variable NPM_TOKEN needs to be set.

NPM_TOKEN=00000000-0000-0000-0000-000000000000

My build stage in gitlab pipelines needs to install a private repository. Thus I put this NPM_TOKEN secret variable in my gitlab pipeline settings.

My current gitlab-ci configuration :

image: x/node

build_job: 
  script:
  - printenv NPM_TOKEN
  - npm i @x/test

The docker image is one that I made it just sets a .npmrc file:

FROM node:latest
COPY .npmrc .  

where I have .npmrc in the same directory:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

I've tried the docker image by:

 run -it myimage bash
 export NPM_TOKEN=...
 npm i @x/test

That works, the private package is installed.

However on gitlab pipelines it does not find the package (404). When the job runs I can clearly see the NPM_TOKEN env variable being printed. So I don't know what's up.

like image 321
Ced Avatar asked Jul 11 '17 14:07

Ced


1 Answers

I changed gitlab-ci to this:

image: dasnoo/node

build_job: 
  script:
  - printenv NPM_TOKEN
  - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
  - npm i @dasnoo/testpriv

and it works. not sre why I had to do that though

like image 62
Ced Avatar answered Oct 25 '22 12:10

Ced