Increment variable value in TFS build +1

五迷三道 提交于 2019-12-22 03:59:48

问题


I have a Microsoft Visual Studio Team Foundation Server (Version 15.117.26714.0) with predefined variable $(ProjectBuildNumber).

Is there any way to increment, during build process, value of variable with minor build number by +1?

$(ProjectBuildNumber)  =   663

So, that on next build it will be:

$(ProjectBuildNumber)  =   664


回答1:


You can't reference variables in the build number of the Build Definition. But what you can do is override the build number in the build itself. You can either use a magic log command or use my VSTS Variables Task to set the Build.BuildNumber in the build itself. The Variables Task does expand variable references. You could probably just set the value to the current value to get it expanded.

To issue the log command yourself use a batch script, PowerShell or bash to output the following specific string to the console:

##vso[build.updatebuildnumber]build number

Update build number for current build. Example:

##vso[build.updatebuildnumber]my-new-build-number

Minimum agent version: 1.88

source: https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md

An alternative option is to use the $(Rev) option:

Build.BuildNumber = 1.1.$(Rev:.r)  

That will automatically increase the variable each time the build runs.

To update a variable in a Build Definition use yet another extension:

These things combined should be able to get what you want.




回答2:


In the variable section,

set the value of ProjectBuildNumber to $[counter('', 663)].

This will queue build starting with 663 as ProjectBuildNumber and increments by 1 for the subsequent queue of builds.



来源:https://stackoverflow.com/questions/50330425/increment-variable-value-in-tfs-build-1

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