TFS 中的日期变量 [英] date variable in TFS

查看:33
本文介绍了TFS 中的日期变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 TFS 中为我​​的任务创建一个变量,用于格式为 yyyymmdd 的时间戳.我知道我使用 bash 或 powershell 专门为此创建了一个任务.但是,我正在寻找一些现有的变量或某种方法来创建此变量,而无需为其设置专门的任务.

I am trying to create a variable in TFS for my task for timestamp in format yyyymmdd. I know that I create a task specifically for this using bash or powershell. However, I am looking to find some existing variable or some way to create this variable without having to setup a task dedicated for itself.

到目前为止,我已经尝试在我的变量中使用 $(Date:yyyymmdd) 但它没有在其中放置值,而是按原样使用变量名.

So far I have tried to use $(Date:yyyymmdd) in my variables but it does not put values in it, it uses variable name as is.

例如 C:\Alpha\beta\$(Date:yyyymmdd) 而不是 C:\Alpha\beta\20191107

For example, C:\Alpha\beta\$(Date:yyyymmdd) instead of C:\Alpha\beta\20191107

谁能帮我解决这个问题?非常感谢

Can anyone help me with this ? Thanks a lot

推荐答案

实际上,因此没有扩展.我们没有这种获取当前日期时间和工作的系统或环境变量.您可能已经注意到您可以使用 $(Date),但是它仅在版本号格式部分可用.其他如 $(Rev:r)$(DateOfYear) 是相同的,不在 BuildNumberFormat-Settings 之外工作..

Actually, it is hence not expanded. We do not have this kind of system or environment variable which get current date time and work every. You may have noticed you could use $(Date), however which is only available in the Build number format section. Others such as $(Rev:r) and $(DateOfYear) are the same, do not work outside the BuildNumberFormat-Settings..

在此处查看所有系统和环境变量的列表:预定义变量

Take a look at the list of all system and environment variables here: Predefined variables

正如您所指出的,您需要在 PowerShell 任务中使用脚本来设置构建定义中的变量,示例:

As you have pointed out, you need to use a script in a PowerShell Task to set a variable in your build definition, a sample:

$date=$(Get-Date -Format 'yyyymmdd');
Write-Host "##vso[task.setvariable variable=time]$date"

然后您可以在后续构建任务中使用 $(time).

Then you can use $(time) in your subsequent build tasks.

更多细节也看看这个类似的问题:VSO(TFS)- 获取当前日期时间作为变量

More details also take a look at this similar question: VSO(TFS) - get current date time as variable

这篇关于TFS 中的日期变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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