简体   繁体   English

在gitlab管道中安装私有npm包

[英]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安装私有存储库, NPM_TOKEN需要设置环境变量NPM_TOKEN

NPM_TOKEN=00000000-0000-0000-0000-000000000000

My build stage in gitlab pipelines needs to install a private repository. 我在gitlab管道中的构建阶段需要安装一个私有存储库。 Thus I put this NPM_TOKEN secret variable in my gitlab pipeline settings. 因此,我将这个NPM_TOKEN秘密变量放在我的gitlab pipeline设置中。

My current gitlab-ci configuration : 我目前的gitlab-ci配置:

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: .npmrc镜像是我设置的.npmrc文件:

FROM node:latest
COPY .npmrc .  

where I have .npmrc in the same directory: 我在同一目录中的.npmrc

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

I've tried the docker image by: 我通过以下方式尝试了docker图像:

 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). 但是在gitlab管道上它找不到包(404)。 When the job runs I can clearly see the NPM_TOKEN env variable being printed. 当作业运行时,我可以清楚地看到正在打印的NPM_TOKEN env变量。 So I don't know what's up. 所以我不知道发生了什么事。

I changed gitlab-ci to this: 我把gitlab-ci更改为:

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 不是为什么我不得不这样做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM