azure-devopsazure-pipelinesazure-pipelines-yamlazure-yaml-pipelines

Use current date in a variable in a yaml pipeline


I would like to create a global variable to define a unique folder name.
Here's the code

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

When I run the pipeline, I get the following message:

format 'yyyy-MM-dd' not valid for 'DateTime' objects

Is there a way to do this? (I'm on Azure Devops Server 2022)


Solution

  • The - within the format is throwing it off.

    Use this:

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

    See format syntax for more details