[英]How to insert a formatted date into the filename of an Azure DevOps "Classic" Release Pipeline?
Note: this is for the Azure DevOps Classic UI, not YAML.注意:这是针对 Azure DevOps经典UI,而不是 YAML。 I'm creating an Azure Release Pipeline ... how do we add a formatted date to a filename?
我正在创建 Azure 发布管道……我们如何将格式化的日期添加到文件名中? At work, we are still using the Classic UI, and YAML is not a choice at this moment.
在工作中,我们仍然使用经典 UI,此时 YAML 不是一个选择。
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).在存档任务中,我想将格式化日期附加到 zip 文件名,因此输出 zip 名称可能是
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,在一个单独的项目中,在构建管道中的“变量”选项卡中,我成功创建了一个变量,并为其分配了一个格式化日期的值,如下所示,
, 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.我也尝试使用 Powershell 添加一个变量,就像这里找到的答案一样,但它不起作用。 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?
编辑:在链接中使用该技术后,它现在可以工作了......我想知道问题是否出在“变量”选项卡中创建变量,然后在 powershell 中使用相同的变量? Or maybe it was a typo?
或者它可能是一个错字?
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). 1,我回到变量选项卡并删除了先前创建的名为“backupDateTime”的变量,该变量填充了“none”值(以下是其他一些示例)。 Anyway, i deleted that variable.
无论如何,我删除了那个变量。
2, I went back into the inline powershell script and added this 2,我回到内联powershell脚本并添加了这个
$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. 3,最后,在需要日期的文件名中,添加了
$(backupDateTime)
,它按预期工作。
Not an original solution, but it's fixed.不是原始解决方案,但已修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.