自定义 TFS 环境变量不读取 $(Date) [英] Custom TFS Enviroment Variable doesn't read $(Date)
问题描述
我想使用这样的自定义 tfs 变量:
合并版本:$(BuildVersion.Major).$(BuildVersion.Minor).$(Date:yy)$(DayOfYear)$(Rev:.r)
我的问题是 $(Date)
、$(Rev:r)
和 $(DateOfYear)
在BuildNumberFormat-设置.
我的结果是:
<块引用>无效的版本字符串:'1.0.$(Date:yy)$(DayOfYear)$(Rev:.r)'.
虽然使用这里显示的 buildnumberformat - 正常工作:
结果 $(Build.BuildNumber)
是 MyBuildName_1.0.18004.15
某些令牌仅在Build number format
部分可用,例如$(Date)
,$(Rev:r)
和 $(DateOfYear)
你在这里提到的.请参阅
I want to use a custom tfs variable like this:
MergedVersion: $(BuildVersion.Major).$(BuildVersion.Minor).$(Date:yy)$(DayOfYear)$(Rev:.r)
My problem is that $(Date)
, $(Rev:r)
and $(DateOfYear)
don't work outside the BuildNumberFormat-Settings.
My result is:
invalid version string: '1.0.$(Date:yy)$(DayOfYear)$(Rev:.r)'.
While with the buildnumberformat like shown here - works correctly:
Result $(Build.BuildNumber)
is MyBuildName_1.0.18004.15
Some tokens are only available in the Build number format
section, such as $(Date)
, $(Rev:r)
and $(DateOfYear)
you mentioned here. See Build definition options
As a workaround, to use $(Rev:r)
you can set the build number format as $(Rev:r)
, then use the $(Build.BuildNumber)
variable in your tasks.
To use $(Date:yy)$(DayOfYear)
, you can set the variables via PowerShell task as ChamindaC mentioned above.
- Add a PowserShell task in you build definition
- Copy and paste below script and save it as
*.ps1
file Check in the PS file, then run the PS file in PowerShell task
$time=$(Get-Date -Format 'yy') # you can set the date format based on your requirement $doy = (Get-Date).DayofYear Write-Host "##vso[task.setvariable variable=Date]$time" Write-Host "##vso[task.setvariable variable=DayOfYear]$doy"
Then you can use the variables $(Date)
and $(DayOfYear)
in other build tasks.
这篇关于自定义 TFS 环境变量不读取 $(Date)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!