Docker部署的Jenkins如何更新版本

1. 安装Jenkins
docker-compose.yml

version: '3.1'
services:
  jenkins:
    restart: always
    image: jenkins/jenkins:centos.v1
    container_name: jenkins
    ports:
      # 发布端口
      - 12012:8080
      # 基于 JNLP 的 Jenkins 代理通过 TCP 端口 50000 与 Jenkins master 进行通信
      #- 50000:50000
    environment:
      - "TZ=Asia/Shanghai"
      - "PATH=$PATH:$HOME/bin:/var/local/apache-maven-3.6.3/bin"
    volumes:
      - ./data:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker


启动命令docker-compose up -d

2. 进入容器更新Jenkins版本
首先,进入容器,记得一定用root用户

[root@iZ8vbi9mx98t2q4hbta56aZ war]# docker cp jenkins.war jenkins:/root/
[root@iZ8vbi9mx98t2q4hbta56aZ war]# docker exec -u root -it jenkins bash


其次,执行命令查看java进程

[root@47faa9548aa0 /]# cd /root/
[root@47faa9548aa0 ~]# ps -ef|grep java
jenkins      7     1  0 Mar12 ?        00:04:22 java -Duser.home=/var/jenkins_home -Djenkins.model.Jenkins.slaveAgentPort=50000 -jar /usr/share/jenkins/jenkins.war
root      1012   994  0 16:35 pts/0    00:00:00 grep --color=auto java


这里就能发现,其实容器里面就是使用java启动了jenkins.war包,那么我们升级/usr/share/jenkins/jenkins.war就可以了。

3. 容器里面下载最新的war包
进入官网查看下载jenkins download
通过F12发现下载最新版本链接就是:http://mirrors.jenkins.io/war-stable/latest/jenkins.war
本地下载后上传服务器,并拷贝到容器中

[root@iZ8vbi9mx98t2q4hbta56aZ war]# docker cp jenkins.war jenkins:/root/
[root@iZ8vbi9mx98t2q4hbta56aZ war]# docker exec -u root -it jenkins bash

[root@47faa9548aa0 /]# cd /root/
[root@47faa9548aa0 ~]# ps -ef|grep java
jenkins      7     1  0 Mar12 ?        00:04:22 java -Duser.home=/var/jenkins_home -Djenkins.model.Jenkins.slaveAgentPort=50000 -jar /usr/share/jenkins/jenkins.war
root      1012   994  0 16:35 pts/0    00:00:00 grep --color=auto java


[root@47faa9548aa0 ~]#  cd /usr/share/jenkins/
[root@47faa9548aa0 jenkins]# cp jenkins.war jenkins.war.22.3.17.bak
[root@47faa9548aa0 jenkins]# ls
jenkins.war  jenkins.war.22.3.17.bak  ref
[root@47faa9548aa0 jenkins]# mkdir other-version
[root@47faa9548aa0 jenkins]# cd other-version/
[root@47faa9548aa0 other-version]# cp /root/jenkins.war .

4. 删除原war包,使用新的替换即可

[root@47faa9548aa0 other-version]# cd /usr/share/jenkins
[root@47faa9548aa0 jenkins]# ls
jenkins.war  jenkins.war.22.3.17.bak  other-version  ref
[root@47faa9548aa0 jenkins]#  rm jenkins.war
rm: remove regular file 'jenkins.war'? y
[root@47faa9548aa0 jenkins]# cd other-version
[root@47faa9548aa0 other-version]# mv jenkins.war ../
[root@47faa9548aa0 other-version]# cd ..
[root@47faa9548aa0 jenkins]# ls
jenkins.war  jenkins.war.22.3.17.bak  other-version  ref
docker-compose stop
docker-compose up -d

遇到问题

java.lang.IllegalStateException: An attempt to save the global configuration was made before it was loaded
	at jenkins.model.Jenkins.save(Jenkins.java:3519)
	at jenkins.model.Jenkins.saveQuietly(Jenkins.java:3546)
	at jenkins.model.Jenkins.setSecurityRealm(Jenkins.java:2743)
	at jenkins.model.Jenkins$15.run(Jenkins.java:3481)
	at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:175)
	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:305)
	at jenkins.model.Jenkins$5.runTask(Jenkins.java:1156)
	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:222)
	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:121)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused: org.jvnet.hudson.reactor.ReactorException
	at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:291)
	at jenkins.InitReactorRunner.run(InitReactorRunner.java:49)
	at jenkins.model.Jenkins.executeReactor(Jenkins.java:1191)
	at jenkins.model.Jenkins.(Jenkins.java:981)
	at hudson.model.Hudson.(Hudson.java:86)
	at hudson.model.Hudson.(Hudson.java:82)
	at hudson.WebAppMain$3.run(WebAppMain.java:247)
Caused: hudson.util.HudsonFailedToLoad
	at hudson.WebAppMain$3.run(WebAppMain.java:264)

下载hpi文件,并将其放到JENKINS_HOME/plugins文件夹。jenkins plugin文件夹一般在下面位置:docker/jenkins/data/plugins

Role strategy hpi plugin的下载链接为

https://updates.jenkins.io/latest/role-strategy.hpi

Docker部署的Jenkins如何更新版本_第1张图片

 

你可能感兴趣的:(docker,jenkins,docker,运维)