I'm using GitVersion 5.3.7 from gitversion-ubuntu.18.04-x64-5.3.7.tar.gz to try and generate version numbers for my application.
I'm using TeamCity as a build server.
I'd like to ensure that the version numbers are unique for every build, as there's scenarios where once a version number has been used, it can't be used on a subsequent build. This covers all the version numbers, both semver, as well as assembly, nuget, and the one put back into TeamCity.
TeamCity agent is populating BUILD_NUMBER just fine, and I've managed to get some of the version numbers to include BUILD_NUMBER, but other parts insist on using CommitsSinceVersionSource.
Is there a way for me to override this value, or otherwise achieve what I'm trying to do?
$ BUILD_NUMBER=293 ./gitversion /nocache
{
"Major":0,
"Minor":1,
"Patch":0,
"PreReleaseTag":"ci.3",
"PreReleaseTagWithDash":"-ci.3",
"PreReleaseLabel":"ci",
"PreReleaseNumber":3,
"WeightedPreReleaseNumber":55003,
"BuildMetaData":"",
"BuildMetaDataPadded":"",
"FullBuildMetaData":"Branch.master.Sha.a37ed2018d2712cdc9d10eb200973a49f1d0f2e1",
"MajorMinorPatch":"0.1.0",
"SemVer":"0.1.0-ci.3",
"LegacySemVer":"0.1.0-ci3",
"LegacySemVerPadded":"0.1.0-ci0003",
"AssemblySemVer":"0.1.0.293",
"AssemblySemFileVer":"0.1.0.293",
"FullSemVer":"0.1.0-ci.3",
"InformationalVersion":"0.1.0.293+ci-master.sha.a37ed20",
"BranchName":"master",
"EscapedBranchName":"master",
"Sha":"a37ed2018d2712cdc9d10eb200973a49f1d0f2e1",
"ShortSha":"a37ed20",
"NuGetVersionV2":"0.1.0-ci0003",
"NuGetVersion":"0.1.0-ci0003",
"NuGetPreReleaseTagV2":"ci0003",
"NuGetPreReleaseTag":"ci0003",
"VersionSourceSha":"735742e49e2de35b3832761228cb17a51e677d59",
"CommitsSinceVersionSource":3,
"CommitsSinceVersionSourcePadded":"0003",
"CommitDate":"2020-08-25"
}
As you can see, these three are working fine:
"AssemblySemVer":"0.1.0.293",
"AssemblySemFileVer":"0.1.0.293",
"InformationalVersion":"0.1.0.293+ci-master.sha.a37ed20",
But these are not:
"SemVer":"0.1.0-ci.3",
"LegacySemVer":"0.1.0-ci3",
"LegacySemVerPadded":"0.1.0-ci0003",
"FullSemVer":"0.1.0-ci.3",
"NuGetVersionV2":"0.1.0-ci0003",
"NuGetVersion":"0.1.0-ci0003",
Either SemVer or FullSemVer is being used in teamcity.
If I could provide a format string for these, like I can for others - then that'd solve my issue.
At the moment it looks like my only solution is to compile a version of the app hacking src/GitVersionCore/VersionCalculation/VariableProvider.cs to do what I want.
Configuration:
assembly-versioning-scheme: MajorMinorPatchTag
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: '{Major}.{Minor}.{Patch}.{env:BUILD_NUMBER ?? 9999}+{PreReleaseLabel}-{EscapedBranchName}.sha.{ShortSha}'
assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{env:BUILD_NUMBER ?? 9999}'
assembly-versioning-format: '{Major}.{Minor}.{Patch}.{env:BUILD_NUMBER ?? 9999}'
mode: ContinuousDeployment
increment: Inherit
#continuous-delivery-fallback-tag: ci
branches: {}
# master:
# tag: ci
ignore:
sha: []
merge-message-formats: {}
It's not possible to change the value of SemVer (and thus FullSemVer) since the version number 1.2.3.4 is an invalid SemVer 2.0 version number. At its core, I think it's important that the SemVer provided by GitVersion is guaranteed to be SemVer 2.0 compliant.
What can be discussed, though, is whether the version number exposed to TeamCity needs to be FullSemVer:
I don't think it does, but it's not clear how a change here should be made possible. It would probably have to involve some sort of configuration, which I'm hesitant to add. Would it be possible to perhaps just write your own version number to the log? I have hope that the last line writing buildNumber to the log, wins.
I don't know why, but when I looked for the teamcity integration last night I couldn't see it...
So I went and added format strings for the rest of the bits on my fork.
I don't know if you're interested in merging it in:
https://github.com/GitTools/GitVersion/compare/master...willhughes-au:more-format-strings
Perhaps your use case is more along the lines of what's being discussed in #2065?
Thanks, but no not really.
I ended up abandoning GitVersion since even after I solved the formats that I wanted, I couldn't see a way to make version number incrementing work like I expected and ran out of time for testing/experimenting.
For some reason commits on 'master' and commits on 'develop', despite not merging kept bumping each other's major version numbers.
Anyway, I'll close the issue.