4

im not using yaml, because my companie uses TFVC, so i need the classic way.

With $[pipeline.startTime] i get the starttime, but now i need it formated in this way: dd.MM.yyyy

a powershellscript like in VSO(TFS) - get current date time as variable helped me, but set the day directly in the variables would be a cleaner way

Steini
  • 305
  • 1
  • 3
  • 9
  • Are you trying to set the date on a pipeline variable and you are saying what you are setting is in the format you provided? Have you looked at this already? Using ParseExact. https://stackoverflow.com/questions/27741810/string-to-datetime-conversion-in-powershell – Matt Jul 09 '20 at 16:22
  • How about the issue? Does the answer below resolved your question, If not, would you please let me know the latest information about this issue? – Leo Liu-MSFT Jul 10 '20 at 09:50

2 Answers2

7

How can i set a Azure DevOps Pipeline Varible which contains the date in this Format: 25.07.2020

Since you are using the classic way, nested variables are not supported in the build pipeline. So, we could not use the variables like $(Get-Date -Format Date:MMddyy) to set the date time.

We could only set the variable like:

$[format('{0:ddMMyyyy}', pipeline.startTime)]

In this way, we could get the value 10072020, not the 10.07.2020 without .. And I could not add any interval between ddMMyyyy, it does not supported by Azure pipeline.

Besides, as workaround, we could defined the Build number format in the Options tab with value $(DayOfMonth).$(Month).$(Year:yyyy):

enter image description here

Then we could use variable $(Build.BuildNumber) directly to get the date time:

enter image description here

Hope this helps.

Leo Liu-MSFT
  • 62,538
  • 8
  • 91
  • 107
4

You can define a Azure DevOps Pipeline Variable by using expressions: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops It supports .NET custom date and time format specifiers:

$[format('{0:dd}.{0:MM}.{0:yyyy}', pipeline.startTime)]
korvalds
  • 41
  • 1