自学内容网 自学内容网

docker方式 部署jenkins服务,实现持续集成(CI/CD)功能

一、背景:

因公司需求,需要部署一套jenkins自动化部署服务,并且是通过docker容器的方式部署的。

二、jenkins简介:

什么是Jenkins ?

 Jenkins是一个开源软件,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件项目可以进行持续集成( CI/CD)。

三:CICD流程简介: 

持续集成( CI/CD)是什么?

CI(Continuous Integration)始终指持续集成 ,CD(Continuous Delivery/Continuous Deployment)是持续交付和/或持续部署,总结为如下三点。

  • 持续集成
  • 持续交付
  • 持续部署

cicd基本流程:

四、docker部署jenkins服务:

1、拉取jenkins镜像:

docker search jenkinsci/blueocean

docker pull jenkinsci/blueocean

[root@iZwz9ippftvoxv000lpl0tZ ~]# docker search jenkinsci/blueocean
NAME                  DESCRIPTION                             STARS     OFFICIAL
jenkinsci/blueocean   https://jenkins.io/projects/blueocean   732       
[root@iZwz9ippftvoxv000lpl0tZ ~]# docker pull jenkinsci/blueocean
Using default tag: latest
latest: Pulling from jenkinsci/blueocean
97518928ae5f: Already exists 
f4d84728e541: Already exists 
419d112ff4fa: Already exists 
ecf8c1881f75: Already exists 
78b59c3bfdb7: Already exists 
2ff43df4e763: Already exists 
aac7818be7cc: Already exists 
2913a3e94ae4: Already exists 
f75b1dac4ec0: Already exists 
3d3fbe6f1850: Already exists 
07ef919d711b: Already exists 
5b96e9c30f6a: Already exists 
83dcd37be04b: Already exists 
6beb8929489c: Already exists 
476e95021232: Already exists 
9add339bd1dd: Already exists 
ecb71d48971e: Already exists 
384cd4783059: Already exists 
latest: Pulling from jenkinsci/blueocean
Digest: sha256:f27933313986f7fb0b5784aa6520ebddc455ce258cbf4d13a3e3cf9d4c94d992
Status: Image is up to date for jenkinsci/blueocean:latest
docker.io/jenkinsci/blueocean:latest

 2、部署jenkins服务:

执行部署jenkins容器服务命令:

docker run -p 8080:8080 -p 8081:8081 -p 50000:50000 --name jenkins -v jenkins_data:/var/jenkins_home jenkinsci/blueocean

[root@iZwz9ippftvoxv000lpl0tZ ~]# docker run -p 8080:8080 -p 8081:8081 -p 50000:50000 --name jenkins -v jenkins_data:/var/jenkins_home jenkinsci/blueocean
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2024-04-17 08:01:21.037+0000 [id=1]     INFO    org.eclipse.jetty.util.log.Log#initialized: Logging initialized @675ms to org.eclipse.jetty.util.log.JavaUtilLog
2024-04-17 08:01:21.151+0000 [id=1]     INFO    winstone.Logger#logInternal: Beginning extraction from war file
2024-04-17 08:01:21.183+0000 [id=1]     WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2024-04-17 08:01:21.277+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: jetty-9.4.45.v20220203; built: 2022-02-03T09:14:34.105Z; git: 4a0c91c0be53805e3fcffdcdcc9587d5301863db; jvm 11.0.16.1+1
2024-04-17 08:01:21.620+0000 [id=1]     INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2024-04-17 08:01:21.675+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2024-04-17 08:01:21.675+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2024-04-17 08:01:21.680+0000 [id=1]     INFO    o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
2024-04-17 08:01:22.278+0000 [id=1]     INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2024-04-17 08:01:22.595+0000 [id=1]     INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@1b1637e1{Jenkins v2.346.3,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2024-04-17 08:01:22.638+0000 [id=1]     INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@5b12b668{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2024-04-17 08:01:22.638+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: Started @2278ms
2024-04-17 08:01:22.646+0000 [id=23]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2024-04-17 08:01:22.937+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2024-04-17 08:01:23.318+0000 [id=31]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2024-04-17 08:01:28.570+0000 [id=31]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2024-04-17 08:01:28.630+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2024-04-17 08:01:28.718+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
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-04-17 08:01:30.446+0000 [id=31]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2024-04-17 08:01:30.447+0000 [id=31]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2024-04-17 08:01:30.448+0000 [id=31]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2024-04-17 08:01:30.453+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2024-04-17 08:01:30.496+0000 [id=45]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
2024-04-17 08:01:30.506+0000 [id=45]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Download metadata. 8 ms
2024-04-17 08:01:30.601+0000 [id=30]    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:

436c75eef44d4db1a72f47da0300f659

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2024-04-17 08:01:46.417+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
2024-04-17 08:01:46.532+0000 [id=22]    INFO    hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running

注意这里可以获取Jenkins控制台登陆密码,后面会需要用到。

3、登入jenkins服务:

这样利用你访问机器的IP地址+8080 即可出现jinkens的界面

 会显示如下的内容

这里需要输入上面的获取到密码:436c75eef44d4db1a72f47da0300f659 

4、初始化jenkins服务: 

上面输入密码之后就会跳转到如下界面
注:这里选择推荐的插件

选择之后弹出如下:

创建一个管理员用户: 

 

保存之后,需要重启一下jenkins服务。然后登入一下jenkins。

到此,jenkins服务的部署就完成了。


原文地址:https://blog.csdn.net/jiang0615csdn/article/details/137872662

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!