Getting 404 error trying to publish package on CI/CD

Hi!

I want to publish a private npm package to gitlab local npm registry. I configurated .npmrc files (local & ci) and gitlab-ci.yml. Publishing from local machine works well.

However, when I have tried to do the same on CI I got next error:

Or if I would try yarn (project package manager):

Also, I have tried to use personal access token on CI instead of CI_JOB_TOKEN for test but It didn’t work.

I have followed all steps described in gitlab publishing documentation but I finally got stacked. What are I missing?

I would be grateful for any advice or help. Thanks in advance!

Configs

GitLab version: 13.6.1

gitlab-ci job:

publishing:
  stage: publishing
  except:
    variables:
      - $CI_COMMIT_MESSAGE =~ /^Publishing.*/
  script:
    - echo @GeekBrainsTeam:registry=https://gitlab.admin.geekbrains.ru/api/v4/projects/${CI_PROJECT_ID}/packages/npm/ >> .npmrc
    - echo //gitlab.admin.geekbrains.ru/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN} >> .npmrc
    - docker run --rm ${IMAGE_NAME} yarn build
    - docker run --rm ${IMAGE_NAME} yarn version --patch # for example
    - docker run --rm ${IMAGE_NAME} npm publish --verbose

Local .npmrc file:

@GeekBrainsTeam:registry=https://gitlab.admin.geekbrains.ru/api/v4/projects/<id>/packages/npm/
//gitlab.admin.geekbrains.ru/api/v4/projects/<id>/packages/npm/:_authToken=<my_token>
//gitlab.admin.geekbrains.ru/api/v4/packages/npm/:_authToken=<my_token>

package.json:

{
"name": "@GeekBrainsTeam/geekbrains-uikit",
  "version": "0.1.0",
  "description": "React-components library for GeekBrains projects",
  "repository": {
    "type": "git",
    "url": "https://gitlab.admin.geekbrains.ru/GeekBrainsTeam/geekbrains-uikit.git"
  },
  "publishConfig": {
    "access": "restricted",
    "directory": "lib",
    "@GeekBrainsTeam:registry": "https://gitlab.admin.geekbrains.ru/api/v4/projects/<id>/packages/npm/"
  }
...

I don’t know why need docker run? If don’t need it, just do this

publishing:
  stage: publishing
  except:
    variables:
      - $CI_COMMIT_MESSAGE =~ /^Publishing.*/
  script:
    - echo @GeekBrainsTeam:registry=https://gitlab.admin.geekbrains.ru/api/v4/projects/${CI_PROJECT_ID}/packages/npm/ >> .npmrc
    - echo //gitlab.admin.geekbrains.ru/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN} >> .npmrc
    - yarn build
    - yarn version --patch # for example
    - npm publish --verbose

if your other jobs image it not node, you can set image for the job

publishing:
  stage: publishing
  image: node:latest
  except:
    variables:
      - $CI_COMMIT_MESSAGE =~ /^Publishing.*/
  script:
    - echo @GeekBrainsTeam:registry=https://gitlab.admin.geekbrains.ru/api/v4/projects/${CI_PROJECT_ID}/packages/npm/ >> .npmrc
    - echo //gitlab.admin.geekbrains.ru/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN} >> .npmrc
    - yarn build
    - yarn version --patch # for example
    - npm publish --verbose

if you really need to run in docker, you should mount .npmrc to docker inside
hit: use -v flag, more info: Use volumes | Docker Documentation

Thank you for the answer! I found the problem: I didn’t have necessary variables in docker container