在Linux服务器上安装Jenkins
本文主要介绍在Linux服务器上安装jenkins,采用在Tomcat上部署Jenkins.war包的方式进行安装。服务器上之前已安装JDK等基础环境,此处不再赘述。
安装包下载
Tomcat:本文使用的Tomcat9
Jenkins:点击下载
Tomcat安装
将下载的Tomcat的软件包解压,然后执行bin目录下的startup.sh脚本,启动Tomcat。通过浏览器访问Tomcat,看是否正常启动。
Jenkins安装
将下载的Jenkins的软件包拷贝到Tomcat的webapps目录下,重启Tomcat,访问jenkins。
Jenkins配置
系统配置
- 全局工具配置
- 配置maven的setting.xml文件
- 配置JDK
- 配置Git
- 配置Maven
- 配置maven的setting.xml文件
- 创建任务
- 新建任务,输入任务名,选择构建一个自由风格的软件项目,确定
- 源码管理,配置代码仓库的地址,选择鉴权信息。
如果是第一次配置,可点击 添加 - Jenkins 添加鉴权信息
- 构建触发器:根据需要配置触发构建的规则,可以不配置通过手动触发构建。
- 构建环境:配置构建环境信息,可不配置。
- 构建:选择全局工具配置中配置的maven,填写构建目标。如果构建完成需要执行别的操作可以点击 增加构建步骤选择后续操作。
- 构建后动作:配置构建完成后的操作
配置完成后点击保存按钮,任务创建完成。
- 新建任务,输入任务名,选择构建一个自由风格的软件项目,确定
遇到的问题
1. jenkins无法访问
现象:Tomcat可以正常访问,jenkins无法访问。查看Tomcat的运行日志catalina.out有如下报错:
18-May-2020 15:52:02.008 WARNING [http-nio-8080-exec-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/scripts/yui/yahoo/yahoo-debug.js] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 18-May-2020 15:52:02.009 WARNING [http-nio-8080-exec-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/scripts/yui/element/element-debug.js] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 18-May-2020 15:52:02.010 WARNING [http-nio-8080-exec-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/META-INF/MANIFEST.MF] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache
18-May-2020 15:52:06.344 WARNING [Handling GET /jenkins/login from 111.18.96.18 : http-nio-8080-exec-3] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/side-files/hudson/util/HudsonIsLoading/index.html] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 18-May-2020 15:52:06.347 WARNING [Handling GET /jenkins/login from 111.18.96.18 : http-nio-8080-exec-3] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/classes/hudson/util/HudsonIsLoading/login.groovy] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache 18-May-2020 15:52:06.348 WARNING [Handling GET /jenkins/login from 111.18.96.18 : http-nio-8080-exec-3] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/classes/hudson/util/HudsonIsLoading/login.default.groovy] to the cache for web application [/jenkins] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache
解决方法:
修改Tomcat的 conf/context.xml ,在之前添加如下代码:
<Resources cachingAllowed="true" cacheMaxSize="102400" />
2.访问jenkins报错有多个jenkins实例
Jenkins detected that you appear to be running more than one instance of Jenkins
解决方法:
使用ps命令查看Tomcat是否启动了两个,如果是杀掉Tomcat进程后重新启动。
3.nohup启动后台进程失败
问题现象:
使用nohup命令启动后台进程,显示命令执行成功,但是后台进程未启动
问题原因:
jenkins在执行完一次构建后会杀死这次build的所有子进程
解决方法:
在脚本中加入如下代码,修改buildId
BUILD_ID=DONTKILLME