date variable in TFS

一个人想着一个人 提交于 2021-02-10 20:29:04

问题


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.

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.

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

Can anyone help me with this ? Thanks a lot


回答1:


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

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"

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

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



来源:https://stackoverflow.com/questions/58757262/date-variable-in-tfs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!