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?
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