1

Note: this is for the Azure DevOps Classic UI, not YAML. I'm creating an Azure Release Pipeline ... how do we add a formatted date to a filename? At work, we are still using the Classic UI, and YAML is not a choice at this moment.

In an Archive task, I want to append a formatted date to the zip filename, so the output zip name might be MyBackupFile_20211022_0805.zip, (MyBackupFile_yyyyMMdd_HHmmss).

On a separate project, in a Build Pipeline, in the "Variables" tab, I successfully created a variable assigning it a value of a formatted date, like this, enter image description here, but this does not work in a Release Pipeline.

I also tried adding a variable using Powershell like the answer found here, but it doesn't work. EDIT: After using the technique in the link, it now works ... I wonder if the problem was creating the variable in the "Variables" tab, then using that same variable in the powershell? Or maybe it was a typo?

greg
  • 338
  • 7
  • 17

1 Answers1

0

Not exactly sure what solved it but here's what I did.

1, I went back to the variables tab and removed the previously created variable called "backupDateTime" which was populated with a value of "none" (following some other example). Anyway, i deleted that variable.

2, I went back into the inline powershell script and added this

$DateTime = (Get-Date).ToString("yyyyMMdd_HHmm")
Write-Host "##vso[task.setvariable variable=backupDateTime;]$DateTime"

3, lastly, in the filename where a date was needed, added $(backupDateTime), and it worked as expected.

Not an original solution, but it's fixed.

greg
  • 338
  • 7
  • 17