如何用Jenkins自动化部署项目(教程,从零到搭建完成)
基于jenkins实现的自动化部署:
https://blog.csdn.net/qq_37372007/article/details/81586751
https://blog.51cto.com/13859393/2166141
http://blog.sina.com.cn/s/blog_b5fe6b270102v7xo.html
基于shell脚本实现的自动化部署(脚本):
#!/bin/bash echo "-------开始项目部署---------" projectName="jmeterpush" git_path="git@github.com:happyyangyanghappy/jmeterpush.git" cd /home echo "移除${projectName}项目源码" rm -rf $projectName sleep 3 echo "拉取${projectName}分支项目" git clone ${git_path} ${projectName} sleep 3 cd /home/${projectName} echo "编译${projectName}项目" mvn clean install sleep 3 ### 函数案例 killTomcat() { #pid=`ps -ef|grep tomcat|grep java|awk '{print $2}'` #echo "tomcat Id list :$pid" #if [ "$pid" = "" ] #then # echo "no tomcat pid alive" #else # kill -9 $pid #fi #上面注释的或者下面的 cd $TOMCAT_APP_PATH/bin sh shutdown.sh } # 停tomcat echo "关闭tomcat" killTomcat sleep 3 # 删除原有工程 echo "删除tomcat原有工程" rm -rf $TOMCAT_APP_PATH/webapps/${projectName} #rm -f $TOMCAT_APP_PATH/webapps/ROOT.war #rm -f $TOMCAT_APP_PATH/webapps/my-scrum.war sleep 3 # 复制新的工程到tomcat上 echo "复制新的工程到tomcat上" cp home/${projectName} $TOMCAT_APP_PATH/webapps/ sleep 3 echo "编译war包" cd $TOMCAT_APP_PATH/webapps/ mv my-scrum.war ROOT.war sleep 3 # 启动Tomcat echo "启动Tomcat" cd $TOMCAT_APP_PATH/ sh bin/startup.sh sleep 3