Linux环境搭建jenkins实现自动更新war包
1、安装
jenkins rpm包下载:http://pkg.jenkins-ci.org/redhat/
*脚本自动安装一行命令:
sudo rpm -ih jenkins-2.167-1.1.noarch.rpm
*检查是否安装成功:
/usr/lib/jenkins/jenkins.war WAR包
/etc/sysconfig/jenkins 配置文件
/var/lib/jenkins/ 默认的JENKINS_HOME目录
/var/log/jenkins/jenkins.log Jenkins日志文件
*启动jenkins:
sudo service jenkins start
报错:
[aaa@qq.com jenkins]# sudo service jenkins start
Starting Jenkins bash: /usr/bin/java: No such file or directory
[FAILED]
*需要安装配置jdk(百度);
*配置jenkins中jdk路径:
vim /etc/init.d/jenkins
# Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins.
# see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/bin/java
/usr/java/jdk1.8.0_201/bin/java
"
for candidate in $candidates
*配置jenkins的端口号:
vim /etc/sysconfig/jenkins
JENKINS_PORT="18080"
更改后重启jenkins:(sudo service jenkins start
)
*修改jenkins默认操作用户:
vim /etc/sysconfig/jenkins
将JENKINS_USER="jenkins"调整为JENKINS_USER=“root”
*网址打开http://47.105.123.129:18080,第一次登录Jenkins 会要求解锁
打开红色标记中的路径,取出password,填入上图,点击“continue”
vim /var/lib/jenkins/secrets/initialAdminPassword
2、开始使用
自行百度安装jdk、jenkins、tomcat、maven
1,在jenkins中配置maven和jdk环境
(1) 进入配置界面—>【系统管理】—>【全局工具配置】
maven配置xml:
jdk路径配置:
maven路径配置:
上面的步骤完成了就可以直接配置新的项目了
2、创建所要创建的项目
(1)新建maven项目
(2)点击进入项目配置
(3)项目详细配置:General
(4)源码管理
(5)构建触发器(定时触发在这里设置)
(6)build
(7)配置一个tomcat用户,打开tomcat-users.xml
vim /opt/apache-tomcat-8.5.38/conf/tomcat-users.xml
<role rolename="tomcat" />
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="tomcat" roles="tomcat,admin-gui,admin,manager,manager-gui,manager-script"/>
manager-gui #允许访问html接口(即URL路径为/manager/html/)
manager-script #允许访问纯文本接口(即URL路径为/manager/text/)
manager-jmx #允许访问JMX代理接口(即URL路径为/manager/jmxproxy/)
manager-status #允许访问Tomcat只读状态页面(即URL路径为/manager/status/)
(8)配置
Deploy war/ear to a container需要去插件中下载对应插件,还有相关的svn等插件需要去全局插件下载
配置基本完成
可能会遇到的坑:
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://47.105.123.129:10080/manager/text/list
可能原因:
1、 vim /opt/apache-tomcat-8.5.38/conf/tomcat-users.xml tomcat用户权限配置错误;
2、地址绑定,修改apache-tomcat-8.5.5/webapps/manager/META-INF目录下的context.xml文件,注释这段代码。
<Context antiResourceLocking="false" privileged="true" >
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
还有个找不到符号的锅是pom.xml文件中maven配置版本应该为3.3以上;
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>