In my Pipeline test, it is necessary to change the time zone to Japan compliant.
Is there a simple way to change the time zone?
Hi @kud-sta,
Depends on where you want to set the timezone.
If you want to set the system timezone, you can do that with a Script step, just like you would in your Terminal/Command Line.
E.g. in case of macOS: http://apple.stackexchange.com/questions/117994/is-there-a-fast-way-to-switch-system-time-zone-from-the-command-line
sudo systemsetup -settimezone timezone
Let us know if you have any questions!
This works on macOS
sudo systemsetup -settimezone America/Denver
On Ubuntu, thereβs an error
sudo timedatectl set-timezone America/Denver
Failed to create bus connection: No such file or directory
Is there a way to set the timezone on the Ubuntu containers?
Edit: Iβm hoping this solution works
Edit2: nope
@bootstraponline what was the issue with https://serverfault.com/a/94996/221361 ?
There seem to be an even easier solution, setting the TZ
environment variable (see e.g. https://github.com/moby/moby/issues/12084#issuecomment-160265752). Not sure if itβs respected by every tool / by the tool you want to use but it certainly is by date
:
docker run --rm -it bitriseio/docker-bitrise-base bash
root@eb8b4223062f:/bitrise/src#
$ date
Fri Sep 15 12:29:27 UTC 2017
$ export TZ=Europe/London
$ date
Fri Sep 15 13:31:15 BST 2017
$ export TZ=Europe/Budapest
$ date
Fri Sep 15 14:31:50 CEST 2017
You can of course set the TZ
env as an env var in the bitrise config / bitrise.yml
, example:
format_version: "4"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
app:
envs:
- TZ: Europe/Budapest
trigger_map:
- push_branch: '*'
workflow: primary
- pull_request_source_branch: '*'
workflow: primary
workflows:
primary:
steps:
- script@1.1.4:
title: Do anything with Script step
inputs:
- content: date
Running it in the same docker container as above:
$ date
Fri Sep 15 12:35:46 UTC 2017
$ bitrise run primary
βββββββ βββββββββββββββββββ βββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββ βββ βββββββββββββββββββββββββ
βββββββββββ βββ βββββββββββββββββββββββββ
βββββββββββ βββ βββ ββββββββββββββββββββββ
βββββββ βββ βββ βββ ββββββββββββββββββββββ
version: 1.8.0
INFO[12:35:57] bitrise runs in CI mode
INFO[12:35:57] Running workflow: primary
Switching to workflow: primary
+------------------------------------------------------------------------------+
| (0) Do anything with Script step |
+------------------------------------------------------------------------------+
| id: script |
| version: 1.1.4 |
| collection: https://github.com/bitrise-io/bitrise-steplib.git |
| toolkit: bash |
| time: 2017-09-15T12:35:58Z |
+------------------------------------------------------------------------------+
| |
Fri Sep 15 14:35:58 CEST 2017
| |
+---+---------------------------------------------------------------+----------+
| β | Do anything with Script step | 0.51 sec |
+---+---------------------------------------------------------------+----------+
+------------------------------------------------------------------------------+
| bitrise summary |
+---+---------------------------------------------------------------+----------+
| | title | time (s) |
+---+---------------------------------------------------------------+----------+
| β | Do anything with Script step | 0.51 sec |
+---+---------------------------------------------------------------+----------+
| Total runtime: 0.51 sec |
+------------------------------------------------------------------------------+
Iβm not sure. We are using jest snapshots and no method of changing the timezone is helping. Hereβs an example failure:
- May 31, 2037 at 11:59 PM
+ Jun 1, 2037 at 5:59 AM
The jest tests depend on the system time zone. The mac command works fine, linux one doesnβt.
#!/usr/bin/env bash -e
rm /etc/timezone
rm /etc/localtime
TIMEZONE="America/Denver"
export TZ="$TIMEZONE"
echo "$TIMEZONE" > /etc/timezone
cp "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
This is what Iβm using now & it worked for me.
Current default time zone: 'America/Denver'
Local time is now: Fri Sep 15 08:52:42 MDT 2017.
Universal Time is now: Fri Sep 15 14:52:42 UTC 2017.
Glad to hear and thanks for reporting @bootstraponline!
worked with me