docker - jenkins的时区设置问题
PHPz
PHPz 2017-04-21 10:57:47
0
5
1760

在jenkins中配置的任务,从任务log看,发现时间都是按照格林威治时间显示的,jenkins的系统管理中的“系统信息”里,user.timezone也是Etc/UTC。

我的这个jenkins环境是这样的:jenkins server运行在docker container中,host是ubuntu14.04,container使用的镜像也是基于ubuntu14.04的。最初,host和container的时间也是格林威治时间,我通过"sudo cp /usr/share/zoneinfo/PRC /etc/localtime"重新配置了系统的时区,host和container的时间显示就为北京时间了。但是jenkins server里显示的时间依然是格林威治时间,即使是我将container删掉,重新创建,也还是这样。

不知如何才能将jenkins中的时间调整为北京时间?谢谢。

PHPz
PHPz

学习是最好的投资!

reply all(5)
Peter_Zhu

This problem has not been solved. However, because I need to use Beijing time in the script, I used the TZ='PRC' date command to save it to variable display, which only circumvented this problem.

小葫芦

Don’t pretend to be cool upstairs, it’s a scam. I thought it was really unresolved and it almost misled me.
The fundamental reason is that Jenkins uses the jvm time, so it will still be different from the system time that is modified later. Just follow the steps below. I've solved it.

jvm time zone setting under Linux
On a streamlined Linux installation of jre, I found that the time obtained by all java programs was not the system time. Later I found out that the time zone was wrong. The time obtained by the java program is all GMT time, and the system is Beijing time, which should be GMT+8, which is exactly 8 hours different. After searching a lot of information online, there are only two methods:
1. Use java functions to set the time zone in the program.
2. Add the parameter -Duser.timezone=GMT+8 when starting the java program

But you can’t modify the source code of each program to set the time zone. I don’t want to add parameters when every java program starts, it’s too troublesome. Is there no permanent solution?

At first I thought that jre should have a configuration file that saved the time zone configuration, but found nothing. However, jre always has to go to the system to obtain the time zone configuration. So I started to wonder if Java uses the system configuration file in Linux? So go to the /etc/sysconfig directory under the Linux system to see the time zone configuration. It was found that the clock file used to set the time zone is missing. Copy this file from another Linux system and try it, ok. The time of the java program is consistent with the system time. It seems that jre obtains time zone information from the file /etc/sysconfig/clock.

Attached is the clock file content:

ZONE="Asia/Shanghai"
UTC=false
ARC=false

ZONE -- time zone
UTC -- Indicates that the clock is set to UTC.
ARC -- alpha only indicates the use of ARC.

Peter_Zhu
docker run ... -e JAVA_OPTS=-Duser.timezone=Asia/Shanghai

https://github.com/jenkinsci/docker/issues/45

巴扎黑

Submit another method,
1.cd /etc
2.rm localtime
3.localtime -> /usr/share/zoneinfo/Asia/Shanghai
4. Restart the jenkins server on the page, http://jenkins-server:8080/restart

伊谢尔伦

I am using Ubuntu 12.04, installed through the Jenkins deb package.

The modification method is as follows:

sudo sed -i -r 's#JAVA_ARGS="(.*)"#JAVA_ARGS="-Duser.timezone=Asia/Shanghai "#g' /etc/default/jenkins
sudo service jenkins restart

or

sudo sed -i -r 's#JAVA_ARGS="(.*)"#JAVA_ARGS="-Dorg.apache.commons.jelly.tags.fmt.timeZone=Asia/Shanghai "#g' /etc/default/jenkins
sudo service jenkins restart

Since Google was blocked, people rarely read official documents and official wiki

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!