31

I wish to change the time zone of the Jenkins.

I have changed the time zone of the Jenkins installed server, but the Jenkins UI shows the different time.

I need to set the PST time for Jenkins UI. How can I do it?

informatik01
  • 16,038
  • 10
  • 74
  • 104
soundararajan.c
  • 2,538
  • 6
  • 29
  • 51

8 Answers8

69

On Jenkins2 you can set the timezone at runtime via the Groovy Console. Just open "Manage Jenkins >> Script Console" and type

System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'America/Los_Angeles')

for example. Particularly helpful if you have no chance to change the startup variables but have admin rights on the instance. (often found in containerized setups). Only downside: Setting is gone on restart.

Ben Steinert
  • 1,309
  • 1
  • 11
  • 15
14

Login to jenkins and goto right top end and click on the user

then click on the configure and scroll down to last option "User Defined Time Zone" here you can find the different timezones.

I am using jenkins version 2.222.3.

nikhil
  • 216
  • 3
  • 6
13

See https://wiki.jenkins-ci.org/display/JENKINS/Change+time+zone. Jenkins should respect the timezone set for java. But you can force Jenkins to use a specific timezone by adding the following to start command of Jenkins:

java -Dorg.apache.commons.jelly.tags.fmt.timeZone=America/Los_Angeles

This should set your timezone to PST.

Ishmaeel
  • 14,138
  • 9
  • 71
  • 83
Jon S
  • 15,846
  • 4
  • 44
  • 45
  • 1
    I have added as :`JAVA_ARGS="java - Dorg.apache.commons.jelly.tags.fmt.timeZone=America/Los_Angeles" ` below to `JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"` in `/etc/sysconfig/jenkins`.Then restarted jenkins via :`/etc/init.d/jenkins restart` Time not get reflected .Even now jenkins UI shows the time as : **Feb-14-2017 8:49 AM UTC in build logs ** Same is present in the bottom line of the page : **Page generated: Feb 14, 2017 8:50:45 AM UTC** **In jenkins :system logs : user.timezone UTC** – soundararajan.c Feb 14 '17 at 09:10
  • 1
    Try adding `-Duser.timezone=America/New_York` to `JENKINS_JAVA_OPTIONS` in `/etc/sysconfig/jenkins` – Jon S Feb 14 '17 at 09:24
  • Tried by adding,`JENKINS_JAVA_OPTIONS=-Duser.timezone=America/New_York` along with `JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true" ` `JAVA_ARGS="java - Dorg.apache.commons.jelly.tags.fmt.timeZone=America/Los_Ange‌​les" `in `/etc/sysconfig/jenkins.` Then restarted jenkins via :`/etc/init.d/jenkins restart` but time not get reflected in jenkins UI still showing **Feb 14, 2017 9:35:06 AM UTC** curent ptc time **Tue Feb 14 01:38:03 PST 2017** – soundararajan.c Feb 14 '17 at 09:39
  • Did you have two `JENKINS_JAVA_OPTIONS=...`, one for `user.timezone` and one for `java.awt.headless`? Not sure if that is possible. Try: `JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Duser.timezone=America/New_York"` – Jon S Feb 14 '17 at 09:53
  • 1
    `JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Duser.timezone=America/Los_Angeles"` in `/etc/sysconfig/jenkins` **Time changed to PST** – soundararajan.c Feb 16 '17 at 05:28
  • On Jenkins 2.63 `JAVA_ARGS="-Djava.awt.headless=true -Duser.timezone=America/Los_Angeles"` worked for me. – Ankur Agarwal Jun 17 '17 at 17:32
  • 2
    On Ubuntu 16.04, FWIW, the place to edit this is in */etc/default/jenkins*, adding it to *JAVA_ARGS* – Ted Collins Jan 11 '18 at 17:24
3

While trying to find an answer to this, found that an issue is already open for this.

Though the issue status is OPEN, Unresolved, I see an option to use the browser time zone at least for the Console Output time stamps in Jenkins (2.60.2) >> <jobName> >> <build#>:

Use browser timezone

Charles
  • 1,121
  • 19
  • 30
  • 1
    Where is this option? I don't see it anywhere. – Mugen Jun 19 '18 at 04:58
  • @Mugen, as mentioned above, the _Timestamps_ option is available in the **Console Output** page of each build. Please note that you have to have the **Timestamper** plugin installed and the _Add timestamps to the Console Output_ option enabled in the _Build Environment_ section of your build configuration. – Jose P Joseph Sep 18 '18 at 15:17
  • The context of the screenshot fragment in this answer is in the Console Output section of a particular build. This is a tricky and not super useful setting, since it is cosmetic-only per-build. – MarkHu Sep 27 '19 at 00:11
  • For me checking `Use browser timezone` option results in no timestamps in console. Without it timestamps do work. Any ideas? Using FIrefox 77.0.1, Fedora 32. – akostadinov Jun 14 '20 at 19:16
  • I also see that selecting "Use browser timezone" makes the timestamps go away (firefox 78.0.1). Since I really only care about elapsed time between steps, it's not a big deal for me. – David M. Karr Sep 14 '20 at 23:58
1

I am using ubuntu version 16.04 and jenkins version Jenkins ver. 2.164.3 I tried using java -Dorg.apache.commons.jelly.tags.fmt.timeZone=America/Los_Angeles but didn't worked for me. then I ended up using this command- sudo dpkg-reconfigure tzdata this will present you a GUI to set your timezone and then you have to restart jenkins via commands Sudo /etc/init.d/jenkins stop and sudo /etc/init.d/jenkins start

Hope this helps! Cheers prateek

Jay2201
  • 21
  • 1
  • 7
0

I went with the system-wide solution:

I have a bitnami image (which defaults to UTC) running on AWS (in us-east-2). All the work this server does is in my local timezone, and all the people who access it are local. So I changed /etc/timezone and /etc/localtime to Australia/Sydney and restarted Jenkins.

andrew lorien
  • 2,310
  • 1
  • 24
  • 30
0

This section on executing startup scripts serves as a guide in executing typical Script Console code after EVERY bootup. Using this 'trick' will help permanently set properties via Groovy code. This is also easily maintainable.

https://www.jenkins.io/doc/book/managing/groovy-hook-scripts/

Tushar Vazirani
  • 1,011
  • 13
  • 14
0

If you are running Jenkins out of Docker container, then the below Dockerfile setup should work to update the timezone in Jenkins.

FROM jenkins/jenkins:lts-jdk11
USER root

# Install necessary packages
RUN apt-get update && apt-get install -y \
    curl \
    unzip

# update timezone
ENV TZ=Asia/Kolkata
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone


USER jenkins
ENV CASC_JENKINS_CONFIG /usr/share/jenkins/ref/jenkins.yaml
COPY files/jenkins.yaml /usr/share/jenkins/ref/jenkins.yaml
RUN echo 2.0 > /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state
COPY files/InitialConfig.groovy /usr/share/jenkins/ref/init.groovy.d/InitialConfig.groovy
COPY files/plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.txt
Ashwaq
  • 431
  • 7
  • 17