单体应用自动化部署脚本: DATE=$(date +%Y%m% d)time =$(date " +%Y-%m-%d %H:%M:%S " )git clone https: // code.aliyun.com/test/blog.git cd blogmvn clean package if [ $? -ne 0 ]; then echo " 自动化部署blog项目失败,当前日期为
单体应用自动化部署脚本:
DATE=$(date +%Y%m%d) time=$(date "+%Y-%m-%d %H:%M:%S") git clone https://code.aliyun.com/test/blog.git cd blog mvn clean package if [ $? -ne 0 ]; then echo "自动化部署blog项目失败,当前日期为:"$time >> /home/project/blog_deploy.log echo ‘部署失败,请登录服务器查看‘ | mail -s "blog部署" [email protected]163.com else cp -r /home/project/blog/target/blog.war /home/project/tomcat8/webapps/ /home/project/tomcat8/bin/shutdown.sh /home/project/tomcat8/bin/startup.sh rm -r /home/project/blog echo "自动化部署blog项目成功,当前日期为:"$time >> /home/project/blog_deploy.log echo ‘部署成功‘ | mail -s "blog部署" [email protected]163.com fi
其中涉及到邮件在服务器发生,我在这里使用的是heirloom-mailx
安装使用流程如下(以Ubuntu16.04为例):
1.安装heirloom-mailx
apt install heirloom-mailx
2.修改/etc/s-nail.rc并在尾部添加如下内容(这里使用的是163,详情可去163邮箱了解)
set from="[email protected]" set smtp="smtps://smtp.163.com:465" set smtp-auth-user="[email protected]" set smtp-auth-password="123456" set smtp-auth=login
3.测试
echo ‘this is test‘ | mail -s "test email." 123@qq.com
邮箱这里我主要参考:
ubuntu16.04 heirloom-mailx 通过外部SMTP服务器发送邮件