美文网首页
Git自动化部署shell脚本

Git自动化部署shell脚本

作者: 唐岭云 | 来源:发表于2018-07-26 15:05 被阅读423次
    #!/bin/bash
    echo "-------开始项目部署---------"
    projectName="项目名称"
    git_path="项目Git地址"
    pid_no=$(ps -ef | grep tomcat | grep -v grep | awk '{print $2}');
    if [ -n "$pid_no" ];then
     echo "杀死${projectName}进程的编号:${pid_no}"
     kill -9 "$pid_no"
     sleep 2
    else
     echo "当前${projectName}项目已经被关闭"
    fi
    cd /opt/source
    echo "当前${projectName}项目Git地址:" $git_path
    read -t 30 -p  "请输入${projectName}项目的版本号,默认最新请直接回车跳过:" git_version
    echo "移除${projectName}项目源码"
     rm -rf $projectName
     echo "拉取${projectName}分支项目"
     sleep 3
     git clone ${git_path} ${projectName}
     sleep 3
     cd ${projectName}
    if [ -n "$git_version" ];then
     echo "开始切换到指定${git_version}版本号"
     git checkout $git_version
     git show $git_version > info.txt
     cat info.txt
    else
     git show > info.txt
     cat info.txt
     echo "最新版本号"
    fi
    sleep 15
    mvn clean -Dmaven.test.skip=true package
    #nohup mvn tomcat7:run -Dspring.profiles.active=lml >/dev/null 2>&1 &
    sleep 3
    cd /usr/local/tomcat/tomcat/webapps
    rm -rf ROOT ROOT.war
    cp -r /opt/source/${projectName}/target/cqss-breakfast.war /usr/local/tomcat/tomcat/webapps/ROOT.war
    cd /usr/local/tomcat/tomcat/bin
    ./startup.sh
    time=$(date +"%Y-%m-%d")
    tail -f /data/log/breakfast/logs/info.${time}.log
    

    相关文章

      网友评论

          本文标题:Git自动化部署shell脚本

          本文链接:https://www.haomeiwen.com/subject/sbsbmftx.html