0

jenkins流水线配置用户密码的npm私服

 1 year ago
source link: https://blog.shareworld.vip/archives/npm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

jenkins流水线配置用户密码的npm私服

Owen Jia 2023年01月08日 0次浏览

通过jenkins配置react工程流水线部署。

原本构建部署都很简单,npm install&npm run build,dist搬迁到部署路径即可。

相对于自己公司的npm registry,这种registry一般是开启账号/密码,必须要登录进行package依赖下载。在流水线里通过脚本执行命令,是无法人工输入账号密码的。本地手动可以command中断等待输入,流水线完全行不通。

解决方案就出在npm上,npm的命令拉取不同的registry是可以指定的,全局指定一个私服,或者某些前缀依赖拉取指定registry。

npm本身提供机制来解决下载包时的授权问题,文件:.npmrc

npm读取.npmrc的优先级关系:

项目配置文件: /project/.npmrc
用户配置文件:~/.npmrc
全局配置文件:/etc/npmrc

对于.npmrc文件格式:

registry=http://221.238.115.163:18080/verdaccio///http://221.238.115.163:18080/verdaccio/:_auth=LW4gJWluOjEyMzQ1NicgDQo=

这里面的"_auth"是“admin:password"格式,并且base64编码的结果。可以使用命令echo "admin:123"|openssl base64

另外,在_auth机制外还有_authToken方式可以解决。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK