概述
Jenkins 是一个开源项目,提供了一种易于使用的持续集成系统,使开发者从繁杂的集成中解脱出来,专注于更为重要的业务逻辑实现上。同时 Jenkins 能实施监控集成中存在的错误,提供详细的日志文件和提醒功能,还能用图表的形式形象地展示项目构建的趋势和稳定性。
基于jenkins实现pipeline
使用 jenkins 自动化的流程:
- jenkins 上执行构建
- 自动从配置的 git 仓库拉取代码
- 配置脚本打包
- 创建 docker 镜像
- 通过 docker 容器来部署 spring cloud 微服务
1.下载jenkins
下载 jenkins.war 到 /usr/local/jenkins 目录下
- 登录服务器,下载jenkins:
cd /usr/local
wget http://updates.jenkins-ci.org/download/war/2.269/jenkins.war
2.安装jenkins
[root@localhost local]# java -jar jenkins.war --httpPort=8080
Running from: /usr/local/jenkins.war
webroot: $user.home/.jenkins
2020-12-02 01:34:23.879+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @917ms to org.eclipse.jetty.util.log.JavaUtilLog
2020-12-02 01:34:24.185+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2020-12-02 01:34:24.269+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2020-12-02 01:34:24.396+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.33.v20201020; built: 2020-10-20T23:39:24.803Z; git: 1be68755656cef678b79a2ef1c2ebbca99e25420; jvm 1.8.0_272-b10
2020-12-02 01:34:24.952+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2020-12-02 01:34:25.164+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2020-12-02 01:34:25.164+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2020-12-02 01:34:25.165+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
2020-12-02 01:34:26.153+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /root/.jenkins found at: $user.home/.jenkins
2020-12-02 01:34:26.375+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@7b993c65{Jenkins v2.269,/,file:///root/.jenkins/war/,AVAILABLE}{/root/.jenkins/war}
2020-12-02 01:34:26.423+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@90f6bfd{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2020-12-02 01:34:26.423+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @3462ms
2020-12-02 01:34:26.447+0000 [id=21] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2020-12-02 01:34:28.481+0000 [id=26] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2020-12-02 01:34:28.619+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2020-12-02 01:34:31.605+0000 [id=26] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2020-12-02 01:34:31.611+0000 [id=26] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2020-12-02 01:34:31.742+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2020-12-02 01:34:32.351+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2020-12-02 01:34:32.352+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2020-12-02 01:34:32.352+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2020-12-02 01:34:32.366+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2020-12-02 01:34:32.615+0000 [id=40] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2020-12-02 01:34:33.360+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2020-12-02 01:34:33.422+0000 [id=20] INFO hudson.WebAppMain$3#run: Jenkins is fully up and running
2020-12-02 01:34:35.562+0000 [id=40] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2020-12-02 01:34:35.563+0000 [id=40] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Download metadata. 2,947 ms
2020-12-02 01:48:22.260+0000 [id=57] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2020-12-02 01:48:22.261+0000 [id=57] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 1 ms
2020-12-02 02:00:19.478+0000 [id=58] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started telemetry collection
2020-12-02 02:00:19.492+0000 [id=58] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished telemetry collection. 13 ms
3.jenkins配置
打开jenkins页面,需要先解锁:
[root@localhost ~]# cat /root/.jenkins/secrets/initialAdminPassword
c5761e78f88049a58b020acf4599988a
选择安装推荐插件,自动安装:
安装完成
设置用户密码,保存后转到工作页面: