Label Sources with $(GitVersion.NuGetVersion) creates Tag with variable name, not value

情到浓时终转凉″ 提交于 2019-12-06 06:03:55

问题


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?

https://github.com/Microsoft/vsts-agent/issues/716


回答1:


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.




回答2:


Specific steps to achieve my desired result:

  1. Setup VSTS Project/Repository/Build pre-reqs:
    https://www.visualstudio.com/en-us/docs/build/scripts/git-commands#enable-scripts-to-run-git-commands
  2. 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:

  1. Arguments: tag -a $(GitVersion_NuGetVersion) -m "Auto-Tagged v$(GitVersion_NuGetVersion) by Build ($(Build.BuildId))"
  2. Arguments: push origin $(Build.BuildNumber)


来源:https://stackoverflow.com/questions/41026158/label-sources-with-gitversion-nugetversion-creates-tag-with-variable-name-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!