18

I have a Jenkins-ci installation on a debian squeeze.

Current default time zone: 'America/Toronto'
Local time is now:      Mon Jul  9 16:00:57 EDT 2012.
Universal Time is now:  Mon Jul  9 20:00:57 UTC 2012.

In the /etc/default/rcS file i have :

UTC=no

Unfortunately this is not working, In the system information of jenkins:

user.timezone   Etc/UTC

I searched for a few hour.. unfortunately could not find a fix any help would be greatly appreciated.

Thank for your time

2
  • 3
    6.5 years later, I still can't configure my user profile to set the timezone I want to see displayed.
    – Matt
    Jan 15, 2019 at 22:00
  • If the Jenkins is inside container, you can set time-zone with a TZ environment variable. This is working great on Openshift: stackoverflow.com/a/61524226/658497
    – Noam Manos
    Apr 30, 2020 at 13:51

7 Answers 7

17

You need to pass in your required value of user.timezone as a JVM argument when you start Jenkins. The Java command line will look something like:

$JAVA_HOME/java -Duser.timezone="America/Toronto" [other JVM parameters] $JENKINS_HOME/jenkins.jar

Unfortunately I'm not familiar with the Debian installation, but the JVM parameters should either be defined in the /etc/init.d/jenkins script or in a properties file that is referenced from that script.

5
  • 1
    I must add, Jenkins don't like to TimeTravel to the past : Last Sucess: -322 ms (#30)
    – drgn
    Jul 11, 2012 at 20:09
  • Just to let you know, Once Jenkins is not "In the past" anymore time for last success and last failure have been fix by itself. Also I did not used the /etc/init.d/jenkins script. I start all my services in /etc/init.d/rc.local I just added the value of the timezone in my launch command. Once again thank you
    – drgn
    Jul 12, 2012 at 14:55
  • 1
  • 1
    on centos/rhel, you can set in /etc/sysconfig/jenkins: JENKINS_JAVA_OPTIONS="-Duser.timezone=America/New_York"
    – nandoP
    Oct 8, 2014 at 15:46
  • 1
    I don't belive Debian has set up Time zone properly in /etc/init.d/rc.local. Would probably worked of you have had a Sysv init script to start Jenkins. There are some examples on Jenkins website. The UTC=no in /etc/default/rcS has nothing to do with timezone on your machine. It is telling if time stored in hardware clock is the local time or UTC time. About adjusting the time, use ntp or any other NTP-daemon as a client, as it will slowly adjust the time without time travel.
    – Anders
    Feb 18, 2015 at 16:24
11

Three years later, I found several gotchas getting this to work. So, I'll elaborate upon the accepted answer (which is correct) and add a complete answer for CentOS.


Gotcha #1: The Jenkins settings to change

The current Jenkins documentation on changing time zone says to define user.timezone or org.apache.commons.jelly.tags.fmt.timeZone. But, I have found that both are necessary. The jelly one works for Jenkins proper and some plugins, while the user one works for other plugins.


Gotcha #2: The OS settings to update

For CentOS in the Eastern US, edit /etc/sysconfig/jenkins to:

JENKINS_JAVA_OPTIONS="-Dorg.apache.commons.jelly.tags.fmt.timeZone=America/New_York -Duser.timezone=America/New_York"
JENKINS_ARGS=""

If you put these -D settings into JENKINS_ARGS, it won't work.


Gotcha #3: Restarting

You have to restart from the command line, the entire service. Simply doing a Jenkins safe restart is not sufficient. So:

sudo service jenkins restart

When you've done all this, check that both time zone settings match in your Jenkins system information panel: http://jenkins.example.com/systemInfo

1
  • 1
    This helped when running jenkins in a docker container under CentOS but options not set in /etc/sysconfig/jenkins. The options were passed in docker variable in docker run command and then passed to jenkins start command.
    – gaoithe
    Jan 22, 2019 at 17:03
7

In Ubuntu 14.04, none of the above solutions worked for me, but I ended up running the following command, which pulls up an interface where the timezone can be changed from the default (none selected) to something more specific:

sudo dpkg-reconfigure tzdata

First, you're prompted to select the continent, (i.e. America, Asia, etc) and then the city, which in my case resulted in "Asia/Kolkata" for the IST timezone in India.

See UbuntuTime - Using the Command Line.

In addition, after changing the timezone, I restarted Jenkins:

sudo /etc/init.d/jenkins stop sudo /etc/init.d/jenkins start

and then verified that the time was in local IST time. In http://<yourservername>/systemInfo, as provided by user bishop, under the System Properties section, for the "user.timezone" property, I now see "Asia/Kolkata" as its value.

3

If this relates to the execution of jobs based on a cron schedule (ie Build Periodically), you can set you Time Zone in the cron schedule on a per job basis:

TZ=Europe/Dublin
0 7 * * 1-5
2

If you are running Jenkins in Apache Tomcat, add these to <Apache-Tomcat-Dir>/conf/catalina.properties:

user.timezone=America/New_York
org.apache.commons.jelly.tags.fmt.timeZone=America/New_York

Both are needed.

0

For jenkins v2.73.3 on CentOS 7.1 (in docker) we have found you have to both

1. set the OS timezone e.g. 'ln -sf /usr/share/zoneinfo/Asia/Jakarta /etc/localtime' and

2. under Manage Jenkins set the timezone e.g. 'Asia/Jakarta'.

After a regular jenkins:xxxx/restart the new timezone is used.

0

Adding an answer to cover the situation when running jenkins in a docker container under CentOS. In this case options might not be set in /etc/sysconfig/jenkins (depending on your jenkins service start scripts). A jenkins.sh script is used to start the jenkins service. This jenkins.sh script is similar to that used by the jenkins-inside-docker project so this answer is hopefully useful to any jenkins in docker projects deriving from that.

https://github.com/jenkinsci/docker/blob/master/jenkins.sh

Below we get TZ e.g. Europe/Dublin and pass -e $TZ to docker run so that we can have a script which writes that to /etc/timezone or links /etc/localtime but the important thing is passing these two arguments in JAVA_OPTS: "-Dorg.apache.commons.jelly.tags.fmt.timeZone=$TZ -Duser.timezone=$TZ". The jenkins.sh script passes these to the command-line which starts the jenkins process.

On docker host when creating the container example of docker run command:

TZFILE=$(readlink -f /etc/localtime)
TZ=$(echo $TZFILE|sed s#.*zoneinfo\/##)
TZARG=" -e $TZ "

ID=$(docker run $TARG \
-d \
--user=jenkins \
--name jenkins-${USER} \
--restart always \
-p $HOST_IP:$JENKINS_PORT:${JENKINS_PORT_INTERNAL} \
-p $HOST_IP:$JENKINS_SLAVE_PORT:50000 \
$TZARG \
--env JAVA_OPTS="-Dhudson.Main.development=true \
    -Dhudson.footerURL=$JENKINS_URL \
    -Dorg.apache.commons.jelly.tags.fmt.timeZone=$TZ -Duser.timezone=$TZ \
    -Xms800M -Xmx800M -Xmn400M \
    " \
--env JENKINS_HOME=/var/jenkins_home \
-v $JENKINS_DIR:/var/jenkins_home \
$VARGS \
$ADDITIONALARGS \
$IMAGE \
/bin/tini /usr/local/bin/jenkins.sh \
)
echo "INFO: container ID:$ID" |tee JENKINS.CONTAINER.ID

Options were passed in docker variable in docker run command and then passed to jenkins start command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.