最近在研究 jenkins 做流水线打包,费了一番周折终于成功了。但是却发现时间不对。我们现在的项目打包依赖时间戳,这就有可能会有冲突,而且如果该镜像包有问题,就不方便定位了。
因此在网上寻找了一番,找到了这个解决方案,一开始先直接在内部跑命令,时间正常了,第二天上班过来打包一看,时间又不对了。考虑一下,决定还是从 docker run 的时候开始入手。
我现在用的连接
1 docker run --restart=always -u root -d -p 8088:8080 -p 50000:50000 -e JAVA_OPTS=-Duser.timezone=Asia/Shanghai -v /etc/localtime:/etc/localtime -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
我没有直接用参考文章里最后的命令,因为我的工作环境是 macOS,直接用--network=host 无效,mac 和 windows 环境都需要指定端口,所以把需要的语句直接加到我现成的命令中即可。
关键语句是这2条:
1 -e JAVA_OPTS=-Duser.timezone=Asia/Shanghai 2 -v /etc/localtime:/etc/localtime
第一条是指定时区,第二条是映射本地时间。
重新运行后,现在时间又恢复正常了。过两天再看看会不会反复。