LandonSchropp
LandonSchropp

Reputation: 10234

Automatically publish packages to NPM with CircleCI

I'm trying to set up automated deployments for a public NPM package in CircleCI. What I'd like is for CircleCI to automatically publish the package to NPM whenever the version number has changed in package.json has changed. Is that possible with CircleCI?

Upvotes: 1

Views: 1158

Answers (1)

Sam Quinn
Sam Quinn

Reputation: 3871

1 - Obtain the npm authToken for the account that you wish to use to publish the package. You can do that by logging in to npm (npm login). This will save the authToken to the ~/.npmrc file.

2- Go to your project settings in circleci.com, and set the NPM_TOKEN variable to the obtained authToken.

3- In your cicle.yml add a this section

dependencies:
  pre:
    - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc

deployment:
  production:
    branch: master
    commands:
      - npm publish

Whenever you commit to master branch, it will trigger npm publish.

More information in the official documentation

Upvotes: 3

Related Questions