Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish/deploy a npm package to custom artifactory

I want to do something like this:

  1. Create an npm package. Basically, a common code which I want to use for all of my projects. Which I created.
  2. But now What I want is, Every time I commit something in git for this project, Jenkins should build it with updated alpha/beta version and should publish to my own artifactory.
like image 536
Inder Avatar asked May 29 '19 11:05

Inder


People also ask

How do I publish to Artifactory?

Go to the artifact browser, select the repository you want to upload to, and hit the Set Me Up button for instructions. You can upload a file using Artifactory UI. Go to the artifact browser, select the repository you want to upload to, and hit the Upload button for instructions.


1 Answers

Your Jenkins job can be configured to be triggered by a webhook, which would take care of the first part (every time I commit). Depending on which Git server you're using you can find a lot of tutorials how to do that:

  • For GitHub
  • For GitLab
  • For Gogs

please note this is just a random selection of tutorials how to set up the webhook triggers to work with Git servers and by no means an exhaustive list

To publish your package to JFrog Artifactory you can either use the Jenkins Artifactory Plugin, or use the NPM command line. If you want to use the npm command line, you'll need to authenticate first:

# setting the default registry to Artifactory
npm config set registry http://<ARTIFACTORY_SERVER_DOMAIN>:8081/artifactory/api/npm/npm-repo/
# log in
npm login

alternatively you can get a .npmrc file directly from Artifactory using:

curl -u admin:<CREDENTIAL> http://<ARTIFACTORY_SERVER_DOMAIN>:8081/artifactory/api/npm/auth

After that, there are two ways you can push your package to Artifactory:

  • Edit your package.json file and add a publishConfig section to a local repository: "publishConfig":{"registry":"http://localhost:8081/artifactory/api/npm/npm-repo/"}
  • Provide a local repository to the npm publish command: npm publish --registry http://localhost:8081/artifactory/api/npm/npm-repo/
like image 166
retgits Avatar answered Sep 16 '22 16:09

retgits