Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the current date in an Azure Pipeline YAML file to use ase a variable?

I'm trying to inject a useful version number into my ASP Core application which I'm building and deploying using an Azure DevOps pipeline.

- script: dotnet publish -c $(buildConfiguration) -p:Version=2022.06.21 -p:SourceRevisionId=$(Build.SourceVersion)

But I cannot for the life of me work out how to get the date into a variable where I can actually use it. Which is pretty remarkable really since the current date (with some other fluff appended) is what DevOps itself uses for the default build number.

The documentation is horrendous. How do I do this?

like image 399
Neutrino Avatar asked Dec 06 '25 06:12

Neutrino


1 Answers

With the format expression you can transform the pipeline.startTime into a formatted date. In your case, define the variable like the following:

variables:
  currentDate: $[ format('{0:yyyy}.{0:MM}.{0:dd}', pipeline.startTime) ]

Then use the variable like the following:

- script: dotnet publish -c $(buildConfiguration) -p:Version=$(currentDate) -p:SourceRevisionId=$(Build.SourceVersion)
like image 187
JSON Derulo Avatar answered Dec 09 '25 19:12

JSON Derulo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!