-1

let say i have defined few variables in my yaml:

major: 0
minor: 0
patch: $[counter(variables['minor'], 0)] #this will reset when we bump minor
myVersion: '$(major).$(minor).$(patch)-$(Build.BuildId)'

I have few doubts about it's working. I know the value of patch would increment for every build.

But, if i push my changes with the last value of patch as 7, and i create a new branch will the value of patch start from 8 or again 0?

what i want?

  1. value of patch to only increment when i merge my changes to main. (or let's say i have a boolean variable defined in UI. if i set it to true it should increment the patch)
  2. Also, if for the above question, the value of patch starts from 0 from every new branch, then how do i make sure it doesn't?

For example: 0.0.2-XXXX

i have branch A, i ran 20 builds but when i merge my changes to main. the version should be 0.0.3-XXXX, and not 0.0.22.XXXX

Abhishek
  • 29
  • 4
  • Did you refer to the documentation, which explains how the `counter` function works? – Daniel Mann Aug 09 '22 at 19:28
  • Is there any update for this issue? Feel free to let me know if the answer could give you some help. Just a reminder of [this](https://stackoverflow.com/help/someone-answers). – Leo Liu Aug 11 '22 at 01:43

1 Answers1

0

But, if i push my changes with the last value of patch as 7, and i create a new branch will the value of patch start from 8 or again 0?

The counter is related to the current build pipeline not the branch. So, the value of patch start from 8 when you create a new branch.

i have branch A, i ran 20 builds but when i merge my changes to main. the version should be 0.0.3-XXXX, and not 0.0.22.XXXX

Since the counter is related to the current build pipeline, so we need to create a new pipeline and set it as build validation with the counter.

In this case, only when the merge my changes to main, increment counter will work.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135