jenkins使用心得
jenkins基本配置
- 下载jenkins.war包,地址https://jenkins.io/download/
- 放到tomcat相应目录,启动
- 在C:\Users\(当前用户目录).jenkins\secrets 找到初始密码
- 登录到jenkins应用界面
- 系统管理->系统设置中设置相应jdk和maven
目录如需修改也在此
Jenkins的配置好了,插件管理目录在 系统管理->插件管理
需要有的插件:
Maven Integration plugin、Deploy to container Plugin
新增项目操作
1.新建mave项目,如果没有这个选项,请下载Maven Integration plugin插件
2.选中丢弃的构建
3.选择参数化构建过程
添加参数选择 Choices
输入参数名 Choies填 clean dependency:copy-dependencies -DoutputDirectory=lib package install
4.选择源码
5.新增post步骤,此步将生成的代码复制到发布的项目位置
Windows操作脚本:
C:
cd txxzc-jfr\target
copy jfr.war D:\apiTestTomcat\apachetomcat85\webapps
Linux操作脚本
if test $(ps -ef | grep tomcat-7.0.57/conf/logging.pro |wc -l) -eq 1
then
echo “------------no running ,can’t shutdown------------”
else
echo $(ps -ef | grep tomcat-7.0.57/conf/logging.pro |wc -l)
/usr/local/apache-tomcat-7.0.57/bin/shutdown.sh
echo “------------tomcat shutdowning--------------”
sleep 30
if test $(ps -ef | grep tomcat-7.0.57/conf/logging.pro |wc -l) -eq 1
then
echo “------------no running ,can’t kill------------”
else
ps -ef|grep tomcat-7.0.57/conf/logging.pro |cut -c 9-15|xargs kill -s 9
echo “------------tomcat killing--------------”
fi
fi
第二种
/usr/local/apache-maven-3.5.0/bin/mvn clean package
pwd
ps -ef | grep tomcat2 | grep -v grep | awk ‘{print $2}’ | xargs kill -9
cd /usr/local/tomcat2/webapps/
rm -rf gameoflife*
cd /root/.jenkins/workspace/image/gameoflife-web/target/
cp gameoflife.war /usr/local/tomcat2/webapps/
cd /
sleep 2s
export BUILD_ID=dontKillMe
sh /usr/local/tomcat2/bin/startup.sh
6.增加构建后操作,选择Deploy war/ear to a Container
选择tomcat
7.Tomcat配置
在conf文件夹的tomcat-users.xml文件中添加如下代码,给Tomcat配置用户名和密码,热部署必须要有用户名和密码