2

Push and pull into and from your private npm registry via CI pipeline

 1 year ago
source link: https://gist.github.com/silentHoo/8402d470ef48ef8979b8ecd3e5f206e3
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Publish to private npm registry from your CI pipeline

If you want to publish packages to your private registry, e.g. to jfrog.io/Verdaccio/... you should note some important things:

1) Authenticate on your local machine

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.

2) Configure your publish job

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK