Is there a way to set a date and time (timezone) in Azure DevOps CI/CD build pipeline

。_饼干妹妹 提交于 2020-03-22 06:47:07

问题


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?


回答1:


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

The results as seen in the log:

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.

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.




回答2:


using Powershell, you can do:

Get-TimeZone
Set-TimeZone "India Standard Time"
Get-TimeZone


来源:https://stackoverflow.com/questions/56901952/is-there-a-way-to-set-a-date-and-time-timezone-in-azure-devops-ci-cd-build-pip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!