Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 254
PeteBaser Avatar asked Jul 05 '19 11:07

PeteBaser


People also ask

How do I change the time zone in Azure portal?

To do this, add an application setting (using the portal) called “WEBSITE_TIME_ZONE” equal to the name of the time zone in question (basically the same string as the key name at HKLM\Software\Microsoft\Windows Nt\CurrentVersion\Time Zones\). The list of time zone values is here.

How do I schedule a pipeline in Azure DevOps?

To force a pipeline to run even when there are no code changes, you can use the always keyword. Scheduled builds aren't supported in YAML syntax in this version of Azure DevOps Server. After you create your YAML build pipeline, you can use pipeline settings to specify a scheduled trigger. YAML isn't supported in TFS.


1 Answers

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.

like image 71
James Avatar answered Oct 10 '22 13:10

James