如何在Azure Pipeline yaml文件中获取当前日期以使用ASE变量?
我正在尝试将有用的版本编号注入我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用表达式您可以将
pipeline.starttime
转换为格式的日期。在您的情况下,按以下方式定义变量:然后使用以下变量:
With the
format
expression you can transform thepipeline.startTime
into a formatted date. In your case, define the variable like the following:Then use the variable like the following:
它也可以使用以下YAML代码来解决:
当然,您可以根据需要调整上述格式。
然后可以通过宏观语法用作
$(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:
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