自定义 TFS 环境变量不读取 $(Date) [英] Custom TFS Enviroment Variable doesn't read $(Date)

查看:35
本文介绍了自定义 TFS 环境变量不读取 $(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.

  1. Add a PowserShell task in you build definition
  2. Copy and paste below script and save it as *.ps1 file
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆