If you want to publish packages to your private registry, e.g. to jfrog.io/Verdaccio/... you should note some important things:
To authenticate against the private repository, you've to use the npm cli tool. But first you should get your API access token. That's safer than using your password.
npm adduser --registry https://<registry_url>/<api_path>/ --always-auth
- When asked for your user, enter the username.
- As password provide the API token or the account password.
- Provide your email address.
This will authenticate your user account and you'll receive a token that is stored in your local ~/.npmrc
file.
Copy the token from the previous step and add it to your CI tools environment variables. This is called Secret variables in Gitlab:
# This env's are set via your CI tool of choice:
#
# export NPM_REGISTRY_URL_WITHOUT_PROTOCOL = "//<registry_url>/<api_path>/"
# export NPM_REGISTRY_TOKEN = "ey..."
# This snippet is somewhere in your CI job:
cat << EOF > .npmrc
$NPM_REGISTRY_URL_WITHOUT_PROTOCOL:_authToken=$NPM_REGISTRY_TOKEN
EOF
npm publish
To your package.json
you only need to add a `publishConfig so npm knows where to publish the package:
"publishConfig": {
"registry": "https://<registry_url>/<api_path>/"
},
This will publish your package from within the current directory into your private registry. You should make sure that you've write access and updated your package.json
with the new version you want to release.