1

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.

Zomono
  • 772
  • 6
  • 17
  • Have you looked at using something like [gitversion](https://gitversion.net/docs/) already? It can do what you want pretty easily and there are already pipeline tasks you can use for both running the versioning tool and tagging commits. – Matt Jan 05 '22 at 21:31

1 Answers1

1

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)
Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31
  • The main part of the question is to use a minor version in development build that matches the last minor number from the master build plus one. I dont see how your solution achieves that. – Zomono Jan 06 '22 at 09:03
  • In order to write to variable groups you have to access the http api of azure devops from within a pipeline. I don't think this is recommended by azure devops. Thanks anyway for your answer. It helped my making thinks clear. – Zomono Jan 06 '22 at 09:06
  • 1
    @Zomono `I dont see how your solution achieves that.` The main build runs (mj:1;mn:1) then set (mn+1). The dev build runs (mj:1;mn:2;Rev:1).The next dev build runs (mj:1;mn:2;Rev:2). The main build runs (mj:1;mn:2) then set (mn+1). The dev build runs (mj:1;mn:3;Rev:1).The next dev build runs (mj:1;mn:3;Rev:2). – Shamrai Aleksander Jan 06 '22 at 09:12
  • @Zomono `In order to write to variable groups you have to access` There is no problem to update Azure DevOps assets from pipelines. You can manage access for Build Service Account. – Shamrai Aleksander Jan 06 '22 at 09:14
  • 1
    Get the "Ahead of time major variable"-thing now. Thanks. – Zomono Jan 06 '22 at 10:14