Jenkins部署项目
新建任务
配置任务
1.General配置
2.源码管理
3.构建环境
1 2 3 4 5 6 7 8 9 10 11
| 1.Delete workspace before build starts:构建前清空工作空间
2.Use secret text(s) or file(s):使用加密文件或文本
3.Abort the build if it’s stuck:构建出现问题,则终止构建
4.Add timestamps to the Console Output:给控制台输出增加时间戳
5.Inspect build log for published Gradle build scans:检查已发布的Gradle构建扫描的构建日志
6.With Ant:用 Ant
|
4.构建触发器
==<1>.触发远程构建(例如脚本)==
1 2 3
| 该触发方法是指通过调用jenkins接口触发构建任务(token在任务中配置)
curl http://192.168.80.80:8080/job/springboot-quartz/build?token=123456
|
==<2>.其他工程构建后触发==
1
| 该触发方法可以选择在jenkins构建完某个项目时触发构建
|
==<3>.GitHub hook trigger for GITScm polling==
系统管理 》 系统设置
github中生成token
jenkins系统设置中配置 Hook URL
1
| http://p2g1055383.iask.in --> http://192.168.80.80:8080 外网映射
|
github中配置Webhooks地址
==<4>.定时构建==
1 2 3
| 该构建是指在某个时刻定时去构建项目类似定时任务
不管SVN或Git中数据有无变化,均执行定时化的构建任务
|
==<5>.轮训SCM==
1
| 日程表表达式可以参考https://blog.csdn.net/nklinsirui/article/details/95338535
|
5.构建
==<1>.Invoke Ant==
==<2>.Invoke Gradle script==
==<3>.Run with timeout==
==<4>.Set Build status to “pending” on GitHub commit==
==<5>.执行Windows批处理命令==
==<6>.执行Shell==
==<7>.调用顶层Maven目标==
shell脚本构建jar直接运行java -jar项目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #!/bin/bash
SERVER_NAME=quartz
JAR_NAME=quartz-0.0.1-SNAPSHOT
JAR_PATH=/data/jenkins_home/workspace/quartz/target/
JAR_WORK_PATH=/data/run
echo "查询进程id-->$SERVER_NAME" PID=`ps -ef | grep "$SERVER_NAME" | awk '{print $2}'` echo "得到进程ID:$PID" echo "结束进程" for id in $PID do kill -9 $id echo "killed $id" done echo "结束进程完成"
echo "复制jar包到执行目录:cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH" cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH echo "复制jar包完成" cd $JAR_WORK_PATH
chmod 755 $JAR_NAME.jar
BUILD_ID=dontKillMe nohup java -jar $JAR_NAME.jar &
|
shell脚本构建war部署tomcat项目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #!/bin/bash
export BUILD_ID=tomcat_build_id
cd /data/jenkins_home/workspace/qywk/开发源码/Work/qywk-idea
mvn clean install
TOMCAT_PATH=/data/apache-tomcat-8.0.44
SERVER_NAME=qianYuWeiKe-0.0.1-SNAPSHOT
JAR_NAME=qianYuWeiKe-0.0.1-SNAPSHOT JAR_NWE_NAME=qianYuWeiKe
JAR_PATH=/data/jenkins_home/workspace/qywk/开发源码/Work/qywk-idea/qianYuWeiKe/target
JAR_WORK_PATH=/data/run
echo "查询进程id-->$SERVER_NAME" PID=`ps -ef | grep "$SERVER_NAME" | awk '{print $2}'` echo "得到进程ID:$PID" echo "结束进程" for id in $PID do kill -9 $id echo "killed $id" done echo "结束进程完成"
echo "复制jar包到执行目录:cp $JAR_PATH/$JAR_NAME.war $JAR_WORK_PATH" cp $JAR_PATH/$JAR_NAME.war $JAR_WORK_PATH echo "复制jar包完成" cd $JAR_WORK_PATH
chmod 755 $JAR_NAME.war
chmod +x $TOMCAT_PATH/bin/*.sh
cp $JAR_WORK_PATH/$JAR_NAME.war $TOMCAT_PATH/webapps
mv $TOMCAT_PATH/webapps/$JAR_NAME.war $TOMCAT_PATH/webapps/$JAR_NWE_NAME.war
ps -ef |grep tomcat |awk {'print $2'} | sed -e "s/^/kill -9 /g" | sh -
rm $$TOMCAT_PATH/logs/* -rf
rm $$TOMCAT_PATH/work/* -rf
$TOMCAT_PATH/bin/shutdown.sh
$TOMCAT_PATH/bin/startup.sh
tail -f $TOMCAT_PATH/logs/catalina.out
|