有没有一种方法可以在Azure DevOps CI/CD构建管道中设置日期和时间(时区) [英] Is there a way to set a date and time (timezone) in Azure DevOps CI/CD build pipeline
问题描述
我在CI/CD构建管道中运行了自动化测试,但是DevOps中的时间是UTC,而我的断言测试则检查本地时间. 有没有办法在我的构建管道中设置时区?
I have automated test running in my CI/CD build pipeline, but the time in DevOps is UTC and my assertions tests check the local time. Is there a way to set a time zone in my build pipeline?
推荐答案
是.例如,以下简单的BASH脚本使用Microsoft Hosted Agent运行:
Yes. For example this simple BASH script run using a Microsoft Hosted Agent:
echo "checking date"
date
echo "setting date to Asia/Kolkata"
sudo timedatectl set-timezone "Asia/Kolkata"
date
在日志中看到的结果:
2019-07-05T20:26:48.5992486Z checking date
2019-07-05T20:26:48.5992954Z Fri Jul 5 20:26:48 UTC 2019
2019-07-05T20:26:48.5993264Z setting date to Asia/Kolkata
2019-07-05T20:26:48.9107025Z Sat Jul 6 01:56:48 IST 2019
如您所见,您可以在代理上操纵本地时间.我不同意其他张贴者的观点,即在运行测试的情况下这样做肯定是一件坏事.
As you can see, you can manipulate the local time on the agent. I do not agree with the other poster that this is necessarily a bad thing to do in the context of running tests.
您在测试中添加了一些额外的代码来说明本地时间/目标时间,或者可以在构建代理中添加1行并实现相同的目的.
You put some extra code in your tests to account for the local / target time or you could add 1 line into your build agent and achieve the same thing.
这取决于细节,细节决定成败.小心处理时间.
It just depends, the devil is in the details. Be careful with how you handle time.
这篇关于有没有一种方法可以在Azure DevOps CI/CD构建管道中设置日期和时间(时区)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!