自定义TFS环境变量未读$(Date) [英] Custom TFS Enviroment Variable doesn't read $(Date)
问题描述
我想使用这样的自定义tfs变量:
I want to use a custom tfs variable like this:
MergedVersion:$(BuildVersion.Major).$(BuildVersion.Minor).$(Date:yy)$(DayOfYear)$(Rev:.r)
MergedVersion: $(BuildVersion.Major).$(BuildVersion.Minor).$(Date:yy)$(DayOfYear)$(Rev:.r)
我的问题是$(Date)
,$(Rev:r)
和$(DateOfYear)
在BuildNumberFormat-Settings之外不起作用.
My problem is that $(Date)
, $(Rev:r)
and $(DateOfYear)
don't work outside the BuildNumberFormat-Settings.
我的结果是:
无效的版本字符串:'1.0.$(Date:yy)$(DayOfYear)$(Rev:.r)'.
invalid version string: '1.0.$(Date:yy)$(DayOfYear)$(Rev:.r)'.
虽然具有如下所示的buildnumberformat-正常工作:
While with the buildnumberformat like shown here - works correctly:
结果$(Build.BuildNumber)
为MyBuildName_1.0.18004.15
推荐答案
某些令牌仅在Build number format
部分中可用,例如您在此处提到的$(Date)
,$(Rev:r)
和$(DateOfYear)
.请参见构建定义选项
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
作为一种解决方法,要使用$(Rev:r)
,您可以将内部版本号格式设置为$(Rev:r)
,然后在任务中使用$(Build.BuildNumber)
变量.
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.
要使用$(Date:yy)$(DayOfYear)
,您可以通过PowerShell任务将变量设置为上述ChamindaC.
To use $(Date:yy)$(DayOfYear)
, you can set the variables via PowerShell task as ChamindaC mentioned above.
- 在构建定义中添加PowserShell任务
- 复制并粘贴以下脚本,并将其另存为
*.ps1
文件 -
签入PS文件,然后在PowerShell任务中运行PS文件
- 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"
$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"
然后,您可以在其他构建任务中使用变量$(Date)
和$(DayOfYear)
.
Then you can use the variables $(Date)
and $(DayOfYear)
in other build tasks.
这篇关于自定义TFS环境变量未读$(Date)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!