【问题标题】:Publishing npm module on Verdaccio from Docker gitlab CI从 Docker gitlab CI 在 Verdaccio 上发布 npm 模块
【发布时间】:2019-09-17 01:03:25
【问题描述】:

我正在尝试通过在 Docker 中运行的 Gitlab CI 在我的私有 Verdaccio 存储库上发布一个模块。我关注了this tutorial,并在我的主机上生成了令牌(因为将运行作业的容器在管道启动之前不存在)。

image: node:11-alpine

stages:
  - test
  - publish

before_script: 
  - npm set registry http://nodejs.repo.asts.com
  - npm i

test:
  stage: test
  script: 
    - npm run lint
    - npm t
  coverage: '/All files\s*\|\s*(\d{1,3}(?:\.\d+)?)/'

publish:
  stage: publish
  script:
    - echo "//nodejs.repo.asts.com/:_authToken=\"$NPM_AUTH_TOKEN\"" > ~/.npmrc
    - cat ~/.npmrc
    - npm whoami
    - npm publish

作业失败并出现以下错误:

$ npm whoami
npm ERR! code ENEEDAUTH
npm ERR! need auth this command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`

但是cat命令显示令牌有期望值。

我不明白问题是否在于 Verdaccio 不支持令牌或我生成令牌的方式。我还找到了plugin,但我不知道应该如何使用。

我应该如何配置我的 gitlab CI 以在 Verdaccio 上发布包?

【问题讨论】:

  • 我没有真正的答案,但我知道你可以从哪里开始 github.com/verdaccio/docker-examples/tree/master/… 和谁问,请检查提交者
  • 不要将 .npmrc 写入用户文件夹,而是将其写入您要从中发布模块的当前文件夹中。
  • 也对此感兴趣。 @JuanPicado,没有关于 Gitlab CI 和 Verdaccio 的官方文档吗?
  • @Nikita 不,只有插件在我们的 GitHub 组织中,我可以在我们的聊天中保证一些文档或快速帮助。 Gitlab 是最受欢迎的,我按时贡献时间,但我不使用它。
  • @JuanPicado 感谢您的回复。最后它比预期的要容易,实际上对冲提供了一个我没有检查的可行解决方案。我会发布一个答案。

标签: docker npm gitlab gitlab-ci verdaccio


【解决方案1】:

它应该像@Hedge 所说的那样工作:将令牌保存在项目文件夹中的.npmrc 文件中:

image: node:11-alpine

stages:
  - test
  - publish

before_script: 
  - npm set registry http://nodejs.repo.asts.com
  - npm i

test:
  stage: test
  script: 
    - npm run lint
    - npm t
  coverage: '/All files\s*\|\s*(\d{1,3}(?:\.\d+)?)/'

publish:
  stage: publish
  script:
    - echo "//nodejs.repo.asts.com/:_authToken=\"$NPM_AUTH_TOKEN\"" > .npmrc
    - npm whoami
    - npm publish

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-26
  • 2021-04-27
相关资源
最近更新 更多