How to increase a version of an npm package using Azure Devops pipeline

SagiLow picture SagiLow · Oct 10, 2019 · Viewed 14.7k times · Source

The pipeline is triggered by new commits to a master branch and publishes the package
Currently, the version is set manually and I'de be happy to have it set automatically.
What I thought at first was adding the following tasks to the pipeline:

  1. checkout $Build.SourceBranch
  2. run version patch --force
  3. git push

This works and the version is really incremented properly, the thing is, it triggers another run of the pipeline, which will increment again, which will.. you get the idea, endless loop.
Is there a better way for doing that?

Answer

SagiLow picture SagiLow · Oct 11, 2019

I've added the same tasks as mentioned in the question with a small change.
Apparently there is a way to skip the pipeline triggering, see here

So the npm version task looks like this:

version patch -m "Bump version to %s [skip ci]" --force

which prevents the next build from being triggered.

TIP: remember to give the 'author' (Azure DevOps user) permissions to Bypass policies when pushing if any.