After a successful build, having configured the Label Format as $(GitVersion.NuGetVersion)
, the resulting tag is set to $(GitVersion.NuGetVersion)
not the actual expanded value of that variable.
In the build output logging, there are 2 sections/plans: Build, and Finalize Build.
Presumably, all the variable context/state is being lost once the build agent moves to the second section/plan.
How am I supposed to tag the source with the resulting GitVersion if the context of the GitVersion variables are lost during the Finalize Build section?
I answered your question in the issue on GitHub:
I don't think there is anything we can do inside of the GitVersion task about this as long as VSTS doesn't provide an appropriate API. GitVersion currently just defines the variables using the
##vso[task.setvariable]value
command. Variables are explicitely defined in the task context, and therefor available for subsequent tasks, but not outside of the context.A special case is the build number for which a special command exists
##vso[build.updatebuildnumber]build number
which we are using.A workaround can be to add an additional task which adds the tag, which will work since the task will be in the same context and have therefore access to the variable.
Specific steps to achieve my desired result:
- Setup VSTS Project/Repository/Build pre-reqs:
https://www.visualstudio.com/en-us/docs/build/scripts/git-commands#enable-scripts-to-run-git-commands - Git Docs for tagging (for completeness):
https://git-scm.com/book/en/v2/Git-Basics-Tagging
I added 2 Command Line Tasks (a Batch Task would be a better idea) with Tool: git
:
- Arguments:
tag -a $(GitVersion_NuGetVersion) -m "Auto-Tagged v$(GitVersion_NuGetVersion) by Build ($(Build.BuildId))"
- Arguments:
push origin $(Build.BuildNumber)
来源:https://stackoverflow.com/questions/41026158/label-sources-with-gitversion-nugetversion-creates-tag-with-variable-name-no