Set timezone for docker not working

version: 2.1

orbs:
  node: circleci/node@4.5.1

jobs:
  init-and-run:
    docker:
      - image: cimg/node:lts
        environment:
          TZ: "Asia/Shanghai"
    steps:
      - checkout
      - node/install-packages

workflows:
  build:
    triggers:
      - schedule:
          cron: "0 0,12,18 * * *"
          filters:
            branches:
              only: main
    jobs:
      - init-and-run

Schedule jobs are not run at the time I expected,it seems to still use UTC timezone

You are setting the TZ environment variable which will be passed to the docker container used to execute that specific job. That will only set the set the environment variable inside that container when it is running.

The cron schedule trigger at the workflow level is outside of your job’s docker container and won’t have any knowledge of the timezone (or other variables) set inside the container. I’m not aware of any way to set the timezone used for a workflow schedule, and the documentation currently only mentions UTC.
The simplest option is probably to do a timezone calculation from your desired timezone to UTC and set your cron to that.

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.