如何使用gitlab ci发布私有npm软件包? [英] How do I publish a private npm package with gitlab ci?

查看:524
本文介绍了如何使用gitlab ci发布私有npm软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Gitlab CI发布一个私有的npm软件包.

I want to publish a private npm package with Gitlab CI.

我已经为我的npm用户创建了一个身份验证令牌,并将其设置为Gitlab CI设置中的变量 NPM_TOKEN .

I've created an auth token for my npm user and set it as a variable NPM_TOKEN in my Gitlab CI settings.

然后,作业使用注册表和auth令牌创建一个 .npmrc 文件.

The job then creates an .npmrc file with the registry and the auth token.

- npm run build && npm run build:es6
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc
- npm publish

作业失败,并显示以下消息:

The job fails with this message:

npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`

是否可以仅使用身份验证令牌进行发布?

Is it possible to publish with only an auth token?

推荐答案

正如@Amityo所说,而不是手动编辑npmrc文件,

As @Amityo said, rather than manually editing the npmrc file,

npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}

是解决之道,因为否则您可能会编辑错误的npmrc文件.

is the way to go, because otherwise you may be editing the wrong npmrc file.

如果仍然出现身份验证错误,并且确定令牌正确,请检查注册表URL.您可以运行

If you are still getting an authentication error, and are certain that the token is correct, check your registry URL. You can run

npm publish --verbose

其输出将包含类似

npm verb getPublishConfig { registry: 'https://.......' }
npm verb mapToRegistry no registry URL found in name for scope @boxine
npm verb publish registryBase https://.......

如果要发布到npmjs.org,则URL(上面的 ....... )应为 https://registry.npmjs.org/.

If you are publishing to npmjs.org, the URL (....... above) should be https://registry.npmjs.org/ .

如果此注册表URL不适合,请在npmrc文件中查找其他文件.还要确保您没有覆盖 package.json 文件中的注册表!您可以在该文件中搜索 publishConfig .

If this registry URL does not fit, look in your npmrc file for a different one. Also make sure you didn't override the registry in your package.json file! You can search for publishConfig in that file.

这篇关于如何使用gitlab ci发布私有npm软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆