简体   繁体   English

如何在 Azure DevOps“经典”发布管道的文件名中插入格式化日期?

[英]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.

相关问题 How to Use Powershellscript in Azure classic Release pipeline - 脚本文件存储在Azure Devops Secure File - How to Use Powershellscript in Azure classic Release pipeline - script file stored in Azure Devops Secure File Azure DevOps 发布管道 - Azure Devops Release Pipeline Azure Devops-发布流水线 - Azure Devops-release pipeline Azure DevOps:在经典模式下使用 Release Pipeline 时,我无法将变量的值传递给其他任务 - Azure DevOps : while using Release Pipeline in classic mode, I'm not able to pass the value of a variable to other tasks Azure DevOps 发布管道:如何复制到我的 VM - Azure DevOps Release Pipeline: How to copy to my VM 如何在发布管道中的 Azure DevOps 中输出 terraform 输出文件 - How to output terraform output file in Azure DevOps in release pipeline 如何在 Azure DevOps 发布管道中保存测试结果 - How can I save testing results in Azure DevOps release pipeline 如何在 Azure Devops 管道版本中保持 1 年后的令牌有效性? - How to maintain token validity after 1 year in an Azure Devops pipeline release? 如何在 azure devops 扩展 api 中获取当前版本的管道 ID - How to get the pipeline Id of the current release in azure devops extension api 如何在Azure DevOps发布管道中建立连接帐户 - How to connect-azaccount in Azure DevOps release pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM