目录
1、下载、启动容器、更新到最新版本
2、查看初始密码两种方式:
3、默认安装的部分未汉化,删除默认的汉化插件。重启容器,重新安装汉化插件
4、安装 Publish over SSH、docker-build-step 、Docker Commons 插件
5、配置服务器连接信息
6、构建自由风格的软件项目
7、构建异常(“uri was not specified”)并解决
1、下载、启动容器、更新到最新版本
获取最新版Jenkins war包,用于更新旧版本:https://www.jenkins.io/download/。下载上传至服务器。
[root@Tseng-HW ~]# docker pull jenkins/jenkins
………………
[root@Tseng-HW ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins/jenkins latest 55860ee0cd73 2 years ago 442MB
[root@Tseng-HW data]# mkdir jenkins_home
[root@Tseng-HW data]# chmod 777 jenkins_home
-- 打开 服务器对应 1581 端口
[root@Tseng-HW data]# docker run -d -p 50000:50000 -p 1581:8080 --name=jenkins --restart=always -v /data/jenkins_home:/var/jenkins_home -v /etc/localtime:/etc/loacaltime -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v /usr/local/shell:/usr/local/shell jenkins/jenkins
235130a2d962fc40da331e4a567e73ec0eaf7ced50fe3d8266431cd45c412f9e
-- 把最新版本的war包替换到已安装的容器中
[root@Tseng-HW data]# cp jenkins.war /data/jenkins_home/jenkins.war
[root@Tseng-HW data]# docker exec -it -u root jenkins bash
root@235130a2d962:/# cd /usr/share/jenkins/
root@235130a2d962:/usr/share/jenkins# cp jenkins.war jenkinsBAK.war
root@235130a2d962:/usr/share/jenkins# cp /var/jenkins_home/jenkins.war /usr/share/jenkins/
root@235130a2d962:/usr/share/jenkins# exit
exit
[root@Tseng-HW data]# docker restart jenkins
jenkins
[root@Tseng-HW data]#
2、查看初始密码两种方式:
1、查看初始密码文件:cat /data/jenkins_home/secrets/initialAdminPassword
2、查看容器日志:docker logs c53f
[root@Tseng-HW jenkins_home]# cat /data/jenkins_home/secrets/initialAdminPassword
c657baee1a0044ab8f5ee296d2381b85
[root@Tseng-HW jenkins_home]# docker logs c53f
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2024-06-24 06:37:01.666+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @573ms to org.eclipse.jetty.util.log.JavaUtilLog
2024-06-24 06:37:01.777+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2024-06-24 06:37:02.868+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2024-06-24 06:37:02.926+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.43.v20210629; built: 2021-06-30T11:07:22.254Z; git: 526006ecfa3af7f1a27ef3a288e2bef7ea9dd7e8; jvm 11.0.13+8
2024-06-24 06:37:03.190+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2024-06-24 06:37:03.224+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2024-06-24 06:37:03.224+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2024-06-24 06:37:03.226+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
2024-06-24 06:37:03.724+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2024-06-24 06:37:04.047+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@3f049056{Jenkins v2.328,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2024-06-24 06:37:04.087+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@45e37a7e{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2024-06-24 06:37:04.088+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @2999ms
2024-06-24 06:37:04.089+0000 [id=23] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2024-06-24 06:37:04.298+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2024-06-24 06:37:04.348+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2024-06-24 06:37:05.269+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2024-06-24 06:37:05.273+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2024-06-24 06:37:05.282+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2024-06-24 06:37:06.027+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2024-06-24 06:37:06.028+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2024-06-24 06:37:06.028+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2024-06-24 06:37:06.033+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2024-06-24 06:37:06.089+0000 [id=44] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
2024-06-24 06:37:06.121+0000 [id=44] INFO hudson.util.Retrier#start: Attempt #1 to do the action check updates server
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/var/jenkins_home/war/WEB-INF/lib/groovy-all-2.4.21.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2024-06-24 06:37:06.777+0000 [id=28] INFO jenkins.install.SetupWizard#init:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
c657baee1a0044ab8f5ee296d2381b85
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
2024-06-24 06:37:27.036+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2024-06-24 06:37:27.060+0000 [id=22] INFO hudson.WebAppMain$3#run: Jenkins is fully up and running
2024-06-24 06:37:27.863+0000 [id=44] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2024-06-24 06:37:27.864+0000 [id=44] INFO hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
2024-06-24 06:37:27.866+0000 [id=44] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Download metadata. 21,760 ms
Running from: /usr/share/jenkins/jenkins.war
webroot: /var/jenkins_home/war
2024-06-24 06:38:54.411+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2024-06-24 06:38:55.625+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2024-06-24 06:38:55.718+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-10.0.20; built: 2024-01-29T20:46:45.278Z; git: 3a745c71c23682146f262b99f4ddc4c1bc41630c; jvm 11.0.13+8
2024-06-24 06:38:56.065+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2024-06-24 06:38:56.159+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: Session workerName=node0
2024-06-24 06:38:56.665+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2024-06-24 06:38:56.812+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@319c3a25{Jenkins v2.452.2,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2024-06-24 06:38:56.830+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@7a560583{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2024-06-24 06:38:56.846+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started Server@235a0c16{STARTING}[10.0.20,sto=0] @3086ms
2024-06-24 06:38:56.849+0000 [id=23] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2024-06-24 06:38:57.138+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2024-06-24 06:38:57.184+0000 [id=29] INFO hudson.PluginManager#loadDetachedPlugins: Upgrading Jenkins. The last running version was 2.328. This Jenkins is version 2.452.2.
2024-06-24 06:38:57.246+0000 [id=29] INFO hudson.PluginManager#loadDetachedPlugins: Upgraded Jenkins from version 2.328 to version 2.452.2. Loaded detached plugins (and dependencies): [javax-mail-api.hpi, bouncycastle-api.hpi, instance-identity.hpi, javax-activation-api.hpi]
2024-06-24 06:38:57.512+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2024-06-24 06:38:58.809+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2024-06-24 06:38:58.829+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2024-06-24 06:38:58.834+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2024-06-24 06:38:59.436+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2024-06-24 06:38:59.436+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2024-06-24 06:38:59.436+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2024-06-24 06:38:59.439+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2024-06-24 06:38:59.540+0000 [id=29] INFO jenkins.install.SetupWizard#init:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
c657baee1a0044ab8f5ee296d2381b85
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/var/jenkins_home/war/WEB-INF/lib/groovy-all-2.4.21.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2024-06-24 06:39:15.240+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2024-06-24 06:39:15.297+0000 [id=22] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
[root@Tseng-HW jenkins_home]#
安装推荐的插件
IP 默认当前服务器IP地址。可在端口后方加其他字符串
3、默认安装的部分未汉化,删除默认的汉化插件。重启容器,重新安装汉化插件
4、安装 Publish over SSH、docker-build-step 、Docker Commons 插件
5、配置服务器连接信息
测试是否连通
6、构建自由风格的软件项目
添加git 用户名、密码信息,
生成容器,保存容器
构建后动作,执行容器命令,启动容器
Exec command 中内容
image_name=Tseng-gateway
container_name=Tseng-gateway
image_tag=latest
user_dir=/data
archive_dir_name=package-run
docker stop $container_name
docker rm $container_name -f
docker rmi $image_name:$image_tag -f
cd $user_dir/$archive_dir_name && docker load -i $image_name:$image_tag.tar
mkdir -p $user_dir/$container_name
docker run -it --name $container_name \
-e profiles_active=test \
-e jvm_ms=1024m \
--net=host \
-m 1024m \
--privileged=true \
--restart=always \
-v $user_dir/$container_name/output:/usr/local/app/output \
-v $user_dir/$container_name/dump:/usr/local/app/dump \
-d $image_name:$image_tag
docker logs --tail 1000 $container_name
7、构建异常(“uri was not specified”)并解决
构建成功后,制作docker镜像异常:uri was not specified
修改docker.service
命令:vim /lib/systemd/system/docker.service 。
添加:-H tcp://0.0.0.0:23578 -H unix:///var/run/docker.sock
在jenkins管理界面中。系统管理-系统设置-Docker Builder 中,将Docker URL改成
tcp://本机IP:23758
,保存重启docker