1

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

Priyasha
  • 23
  • 4

1 Answers1

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

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62