Azure devops: Increase counter only on master

Viewed 780

I want to automate my versioning in an azure devops pipeline. The way it should work is as follows:

  1. The major number is given as constant and will be increased manually.
  2. The minor number should be incremented for each build of the master branch.
  3. On the develop branch the minor number should not increase, but have always the last value used by the master branch plus one.

(Develop-Build numbers will have an additional increasing revision, but this is not part of the question. I also omit the patch number to make the example shorter.)

Example:

  1. Build master => major 1, minor 1
  2. Build develop => major 1, minor 2
  3. Build develop => major 1, minor 2
  4. Build master => major 1, minor 2
  5. Build develop => major 1, minor 3
  6. Build develop => major 1, minor 3
  7. Build master => major 2, minor 1
  8. Build develop => major 2, minor 2

I already managed the autoincrement only for the master branch like

variables:
  major: 1
  minor: $[counter(variables['major'], 1)]

in combination with the condition

eq(variables['Build.SourceBranch'], 'refs/heads/master')

But I don't know how to get the next counter value from a develop build without incrementing it.

1 Answers

I think, that's not possible with counters and conditions. However, you can consider using variable groups (major and minor) and splitting your build to master and development.

  1. The master build uses major and major then increases minor after completion. (Add & use variable groups, How to Increase/Update Variable Group value using Azure Devops Build Definition?)
  2. The development build uses major and major and adds some autoincrement to the end of your build name (like $(Rev:.r)). (Configure run or build numbers, Versioning Strategy)
Related