This is the way I’m doing my versioning right now
variables:
major: '1'
minor: '1'
revision: $[counter(variables['minor'], 1)] # This will get reset every time minor gets bumped.
${{ if eq( variables['Build.SourceBranchName'], 'master' ) }}:
nugetVersion: '$(major).$(minor).$(revision)'
${{ else }} :
nugetVersion: '$(major).$(minor).$(revision)-$(Build.SourceBranchName)'
major
and minor
are changed manually, and whenever minor
is changed, the revision
resets back to 0, and keeps increasing with every pipeline that is ran. Now this works well if we only worked in master, but it’s not as good when working in separate branches. Because the revision
will keep incrementing even if we’re working in a different branch, and thus the master version will no longer be coherent, skipping versions.
What is a good way to do this sort of automatic versioning? I was thinking of having the branch version be based on the latest master revision, and then keep incrementing a fourth digit after the branch name. Example with master being on 1.0.9
, branch foo
would have versions such as 1.0.9-foo.1
, 1.0.9-foo.2
, and so on.
This is just an idea but I don’t know what’s the best practice here or standard. Any ideas are appreciated
2
Answers
We’ve had good luck with having that revision be a value that increments with every single pipeline run (there’s a variable that does this automatically, but I forget the name at the moment, something like BuildID). Then, per pipeline, have major and minor values manually updated as needed. In practice it’s not confusing at all since each pipeline is essentially its own world. Just keep in mind that the last value is a sequence and may skip in a given pipeline since the value increments per pipeline run across the whole organization.
The counter expression will increment the
revision
value betweendifferent branches
inone pipeline
, hence, when you are back tomaster
branch, the version will no longer be coherent, skipping versions.To achieve your original idea, you cannot use same
counter
expression in all yamls between different branches.You can store the
master version
asvariable
in variable group. Infoo
branch, get this variable value so that it won’t update themaster version
.The
master
yaml, change the variable group id to yours.Then in
foo
branch, use yaml below to update thenugetversion
. it gets thenugetversion
from variable group, and useformat()
to combinenugetversion
andbranchname
to determine the lastpatch
version. Sopatch
version will also increment and reset whennugetversion
update in master branch.So it will have below version as expected:
Pipeline result sample on
master
branch andfoo
branch: