有没有办法在 Azure DevOps CI/CD 构建管道中设置日期和时间(时区) [英] Is there a way to set a date and time (timezone) in Azure DevOps CI/CD build pipeline

查看:26
本文介绍了有没有办法在 Azure DevOps CI/CD 构建管道中设置日期和时间(时区)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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?

推荐答案

是的.例如,这个使用 Microsoft 托管代理运行的简单 BASH 脚本:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆