How to publish/deploy a npm package to custom artifactory
Asked Answered
B

1

10

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.
Bronchitis answered 29/5, 2019 at 11:56 Comment(1)
were you able to get this working?Junk
P
16

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:

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/
Pokelogan answered 29/5, 2019 at 15:46 Comment(2)
which directory or files does npm-publish command upload to artifactory? how can I change those directories and files name or path in npm-publish command?Potheen
@Potheen If I am not wrong, by default it will publish everything. However you can include main field in package.json which will be the entry point when your consumers use your library. On the other hand if you want to restrict while files get uploaded, then you can add files field in package.json. Check this link for more information about these fields. Package.json docsJunk

© 2022 - 2024 — McMap. All rights reserved.