简体   繁体   English

TFS构建powershell脚本步骤:无法访问$(Date:yyyyMMdd)变量

[英]TFS build powershell script step : Not able to access $(Date:yyyyMMdd) variable

I had created auto deployment steps using TFS vNext build system. 我使用TFS vNext构建系统创建了自动部署步骤。 In one step I needs to access $(Date:yyyyMMdd) for some file versioning stuff. 在一个步骤中,我需要访问$(Date:yyyyMMdd)来获取某些文件版本。

Below you can find configuration and error snippet: 您可以在下面找到配置和错误代码段:

配置电源shell脚本步骤

排队构建时出错

So any idea how to access date related variables as argument in PowerShell script step ? 那么任何想法如何在PowerShell脚本步骤中访问与日期相关的变量作为参数?

"$(Date:yyyyMMdd)" is a token for Build number format, not a variable . “$(Date:yyyyMMdd)”是Build号格式的标记 ,而不是变量 So you cannot use it in the build steps. 所以你不能在构建步骤中使用它。

The alternative way to do this is to set the "Build number format" under "General" tab to "$(Date:yyyyMMdd)", the variable "$(Build.BuildNumber)" will be filled with the value of "$(Date:yyyyMMdd)". 另一种方法是将“常规”选项卡下的“内部版本号格式”设置为“$(Date:yyyyMMdd)”,变量“$(Build.BuildNumber)”将填充值“$(日期:年月日)”。 And then you can use "$(Build.BuildNumber)" variable in the build steps. 然后你可以在构建步骤中使用“$(Build.BuildNumber)”变量。

As the error tells you, date is not a function. 正如错误告诉您的那样, date不是函数。 You could set the -fileName parameter in your CompressFile script to: 您可以在CompressFile脚本中将-fileName参数设置为:

Param(
    [string]$fileName = 'Package{0}' -f (Get-Date).ToString('yyyyMMdd')
)

And omit the parameter in the TFS VNext argument list (you can still overwrite it). 并省略TFS VNext参数列表中的参数(您仍然可以覆盖它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM