install private npm package in gitlab pipelines

Viewed 9902

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.

1 Answers
Related