How to publish an NPM package from the CI build pipeline and still automate versioning?

npm publish
npm ci
npm version
npm publish new version
npm publish dist folder
jenkins pipeline npm publish
npm publish same version
npm ci/cd

I can't seem to see the forest behind the trees. I want to have a simple CI pipeline that builds and publishes an NPM package. I use appveyor, but I don't think my issue is specific to it. I simply want my CI script to be performing something like this:

git clone "https://git_repo_url" .
npm run build
npm run test
npm version patch --git-tag-version
npm publish -tag beta

The problem is:

  • If I don't do the npm version patch step, the publishing will fail with the feed already contains the package 'abc' at version 'x.y.z' error.

  • If I do that step, then I'd have to push the new commit (the version change) back to the git repo. Otherwise, it will fail as above next time me or someone else build it. Yet I don't feel like doing git push in the back-end pipeline would be the right thing.

  • Lastly, if this CI script just builds the NPM package without publishing it, how do I consume it in other projects which are depending on it?

What are the industry standard ways of doing this?

For instance, if I need to test a non-production feature version of my package with another project, should I make my CI script to patch the package's package.json with a generated, unique semver-compatible version (without commiting it), and then publish it with an npm tag that would match my git branch name? Is it a good idea?

I did it as below, in my javascript project.

Note: get your key form .npmrc

    image: <your project image>
    stage: publish
        - echo _auth=$NPM_PUBLSH_KEY >> .npmrc
        - echo email=<youremail> >> .npmrc
        - echo always-auth=true >> .npmrc
        # - cat .npmrc
        - npm version --no-git-tag-version $(npm view <yourProject>@latest version)
        - npm version --no-git-tag-version prerelease
        - npm publish
        - build

    image: <your project image>
    stage: build
        - node --version
        - npm --version
        - npm ci
        - npm run build -- --watch=false
        - npm run build:prod

How do you publish your NPM packages from the CI pipeline and , How do you publish your NPM packages from the CI pipeline and still automate git clone "https://git_repo_url" . npm run build npm run test npm version patch Lastly, if this CI script just builds the NPM package without publishing it, how do I the standard HTTP package and how to make basic API calls, but I still don't  NPM is the default registry that comes with Node.js, making it currently the largest package registry in the world. Despite its popularity, NPM still has some issues. Recently I published a new module to NPM and found that needed to manually publish to NPM every time I had an update. I used the most common use … Continued

Answering myself. As suggested in the comment above, I've decided to adopt semantic-release for publishing from master branch.

For building and publishing from development branches, I've created a custom node script to generate a semver-compatible pre-release version based on git commit's hash, current major.minor.patch version and current time:

const cp = require('child_process');
// get current semver version without prerelease suffix
const pkg = require('./package.json');
const curVer = pkg.version.trim().split(/[.-]/).slice(0, 3).join('.');
// get the commit id
const commit = cp.execSync('git rev-parse --short HEAD', {encoding: 'utf-8'}).trim();
console.log(`Package: ${}, version: ${curVer}, commit: ${commit}`);
// generate a new unique semver-compliant version based the commit it and current time
const uniqueVer = `${curVer}-beta-${commit}-${Math.random().toFixed(8).substr(2)}.${}`
// use npm version to update package.json
cp.execSync(`npm version ${uniqueVer} --no-git-tag-version`, {stdio: 'inherit'});
// publish and tag with commit id
cp.execSync(`npm publish --tag ${commit}`, {stdio: 'inherit'});

This way, I can check-in my stuff into my dev branch, have the CI pipeline build and publish the package for me and then consume it with npm install mypackage@commitid. A pseudo-unique version will be generated and published to NPM registry, but the modded package.json will not be checked-in.

This approach should work for me for now, but I'd still be very interested to learn about the best DevOps practices to publish internal/per-release NPM packages with CI during normal development cycle.

How to automate versioning and publication of an npm package, How to automate versioning and publication of an npm package semantic-​release could be that you need to tweak too much your CI setup. master && npm i && run-s validate styleguide:build && git-authors-cli && git add . OverviewIn this post, we’ll go over each step in building a basic software delivery pipeline. To do this, we’ll provide some examples to demonstrate an automated software delivery process with continuous delivery using CircleCI as a continuous integration server, and a package repository on packagecloud.To learn more about fundamental concepts around software packages and package

Continuous Deployment for publishing NPM packages, That is where the build/tests/publishing would run. It is a fully automated version management and package publishing But wait, one important point is still missing: how can you publish to npm or push to git without authentication? You simply cannot run npm login command in your CI pipeline as its an  When publishing new versions of npm packages with your automated pipeline, you need to make sure that the version you’re trying to publish does not already exist in your Azure Artifacts feed.

How to Automate the Publishing Process of NPM Modules using , Despite its popularity, NPM still has some issues. For example, I configured my pipeline to build a Docker image from my project (without using a Installing ci-​publish (NPM module that helped me to make it easier): Increase the version in​, package.json you may increase only the minor part to keep  Once you've registered, sign in to the client and publish the package: $ npm login $ npm publish You can check if everything worked properly by looking up your package at by the name provided in the package.json. The npm publish command publishes all files from the directory, except those added to.gitgnore and.npmignore.

Updating a Maintainable NPM Module with Continuous Integration, [Tweet “”As a followup to publishing an NPM package, here's how you update Continuous integration (CI) is one of those topics that might sound scary and will automatically test/build any changes and deploy to a develop/staging does npm install human-date-range will still get the old stable version. When you publish this package to npm, this file will be picked up and the contents used as the documentation of the package. Now let’s see how to publish this package to the npm registry. Publishing the package. We’re done with the hardest parts of publishing a package.

Continuous package publishing, part II: automated npm publishing , Continuous package publishing, part II: automated npm publishing with CircleCI and how to combine them with CI/CD to build a software delivery pipeline, As an example, we're going to build a NodeJS package that provides a The deploy job will publish a version to the configured npm registry when  To publish your first package to npm, you need to go through these steps: First, you need to have an npm account. Create one here if you don’t have one yet. Second, you need to login to your npm account through the command line.