如何在Azure Pipeline yaml文件中获取当前日期以使用ASE变量?

发布于 2025-02-09 18:46:51 字数 308 浏览 3 评论 0原文

我正在尝试将有用的版本编号注入我的ASP核心应用程序中,该应用程序正在使用Azure DevOps管道构建和部署。

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

但是我不能为自己的一生弄清楚如何将日期变成我可以实际使用它的变量。自当前日期(附加其他绒毛)以来,DevOps本身用于默认构建号码,这确实非常了不起。

该文件很可怕。我该怎么做?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪淡了忧伤 2025-02-16 18:46:51

表达式您可以将pipeline.starttime转换为格式的日期。在您的情况下,按以下方式定义变量:

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

然后使用以下变量:

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

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)
月依秋水 2025-02-16 18:46:51

它也可以使用以下YAML代码来解决:

- name: CurrentDateTime
  value: $(Get-Date -Format yyyy.MM.dd_HHmmss)

当然,您可以根据需要调整上述格式。

然后可以通过宏观语法用作$(CurrentDateTime)

请参阅此开发人员社区帖子: https://devervevelvingercommunity.visualstudio.com/t/how-to-to-to-to-to-to-to-get-get-formatd-date-date-date-into-into-into-into-varial-varable-varail-varable-varail-varail-varail-varail-varar-var-var-var-var-var-var-var-var-var-var-var-var-c- in-a-azure/824760

It can also be solved using below YAML code:

- name: CurrentDateTime
  value: $(Get-Date -Format yyyy.MM.dd_HHmmss)

Of course, you can adjust the above format as per your need.

and then it can be used via macro syntax as $(CurrentDateTime)

Refer to this developer community post: https://developercommunity.visualstudio.com/t/how-to-get-formatted-date-into-variable-in-a-azure/824760

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文