Reputation: 11
I'm trying to publish a test for a npm package but it constantly fails. In my package.json I have named the package after "@username/package_name" and also configured the publishConfig object:
"publishConfig": {
"@username:registry": "https://gitlab.com/api/v4/projects/<projectID>/packages/npm"
},
My CICD YAML file is configured this way:
image: node:latest
stages:
- publish
publish:
stage: publish
before_script:
- echo "@username:registry=http://${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/">.npmrc
- echo "//${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}">>.npmrc
script:
- npm publish
and it fails with
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://gitlab.com/api/v4/projects/<projectID>/packages/npm
Any thoughts on what's wrong?
I've read a lot, tried to downgrade node version to 20, 18 and even 16. I followed tutorials and Gitlab documentation. Nothing seems to work.
Upvotes: 0
Views: 402
Reputation: 41111
As mentioned in the docs don't specify CI_SERVER_PORT
if it's a default port:
When generating the
.npmrc
file, do not specify the port after${CI_SERVER_HOST}
if it is a default port, such as80
for a URL starting withhttp
or443
for a URL starting withhttps
.
So, you should use something like this:
script:
- echo "@username:registry=https://${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/" > .npmrc
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}" >> .npmrc
- npm publish
Upvotes: 0