3

I am trying to publish a module on my private Verdaccio repository from Gitlab CI running in Docker. I followed this tutorial and I generated the token on my host (because the container which will run jobs does not exist until the pipeline starts).

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

The job fails with following error:

$ 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`

But the cat command shows that the token has expected value.

I do not understand if the problem is that Verdaccio does not support tokens or the way I generated it. I also found a plugin but I cannot figure out how should be used.

How should I configure my gitlab CI to publish a package on Verdaccio?

gyc
  • 3,986
  • 4
  • 29
  • 42
Marco Stramezzi
  • 1,611
  • 2
  • 11
  • 28
  • 1
    I have no a real answer, but I know where you can start https://github.com/verdaccio/docker-examples/tree/master/gitlab-verdaccio and whom ask, please check the committers – Juan Picado Feb 06 '19 at 14:00
  • Instead of writing .npmrc to the user folder write it in the current folder you want to publish your module from. – Hedge Feb 07 '19 at 16:51
  • Also interested in this. @JuanPicado, there is no official docs about Gitlab CI and Verdaccio? –  Aug 30 '19 at 13:33
  • @Nikita no, only plugins are within our GitHub organization I could guaranty some documentation or quick help in our chat. Gitlab is the most popular one and I contribute time on time, but I don't use it. – Juan Picado Aug 30 '19 at 13:50
  • 1
    @JuanPicado thanks for the response. Finally it was easier than expected, and actually hedge provided a working solution that I failed to check. I will post an answer. –  Aug 30 '19 at 14:32

1 Answers1

1

It should work as @Hedge said: saving the token in a .npmrc file in the project folder:

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
  • Thanks, the solution is a conjunction between your answer and a lack of knowledge about Gitlab protected tags (https://gitlab.com/gitlab-org/gitlab-runner/issues/3057). – Marco Stramezzi Sep 16 '19 at 15:04