I'm trying to figure out how to use GitVersion to generate build id that is compatible with docker, by default gitversion is using something like this:
0.1.0-branchname.1+380
but + cannot be used in the image tag name. The only reasonable thing I've found under the GitVersion docs is NuGetVersionV2 variable, which does seem to replace + with -, but I'd like to know how to have more control over how gitversion is generating "offset" for the commits
For GitVersion task, based on the test result, it counts all commits of current branch instead of base on previous build or cache, regardless of using Microsoft-Hosted or Self-hosted agent.
The GitVersion task exports other variables, so I’d suggest that you can use other variables as docker image tag instead of BuildId.
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.Major;]0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.Minor;]1
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.Patch;]0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.PreReleaseTag;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.PreReleaseTagWithDash;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.PreReleaseLabel;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.PreReleaseNumber;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.BuildMetaData;]17
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.BuildMetaDataPadded;]0017
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.FullBuildMetaData;]17.Branch.master.Sha.4515221c0e10f3bf3fa4038b9b25e2379080ddf1
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.MajorMinorPatch;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.SemVer;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.LegacySemVer;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.LegacySemVerPadded;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.AssemblySemVer;]0.1.0.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.AssemblySemFileVer;]0.1.0.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.FullSemVer;]0.1.0+17
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.InformationalVersion;]0.1.0+17.Branch.master.Sha.4515221c0e10f3bf3fa4038b9b25e2379080ddf1
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.BranchName;]master
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.Sha;]4515221c0e10f3bf3fa4038b9b25e2379080ddf1
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.ShortSha;]4515221
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.NuGetVersionV2;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.NuGetVersion;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.NuGetPreReleaseTagV2;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.NuGetPreReleaseTag;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.CommitsSinceVersionSource;]17
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.CommitsSinceVersionSourcePadded;]0017
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.CommitDate;]2019-07-10
You also can custom format in GitVersion.yml. For example:
mode: ContinuousDelivery
assembly-informational-format: '{SemVer}-{ShortSha}'
branches: {}
ignore:
sha: []
Then, use $(Gitversion.Informationalversion) (sample data:0.1.0-0322edb) in Docker task (Tags input box)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With