jenkins远程部署Tomcat

maven 命令

clean package

 

shell 命令

 

#!/usr/bin/expect
#环境配置部分
set remote_ip your_host
set port your_port
set username yours
set password yours

set target_dir your_target
set war_name uip.war
set tomcat_name tomcat_name
set jenkins_workspace /Users/yugj/.jenkins/workspace
set job_name remote-deploy

set timeout 30
spawn scp -P $port $jenkins_workspace/$job_name/target/$war_name $username@$remote_ip:$target_dir
expect {
    "*yes/no*" {
        send "yes\n"
        expect "*password:"
        send "$password\n"
    }
    "$username@$remote_ip's password:" {
        send "$password\n"
    }
}
set timeout 60
expect eof

spawn ssh -p $port $username@$remote_ip
set timeout 30
expect {
    "*yes/no" {
        send "yes\n"
        expect "*password:"
        send "$password\n"
    }
    "*password:" {
        send "$password\n"
    }
}
expect "Last*"
send "
cd $target_dir

ls | grep -v $war_name | xargs rm -rf

unzip $war_name

rm -rf $war_name

ps aux | grep java | awk '/$tomcat_name/{print \$2}'|xargs kill -9

/usr/local/$tomcat_name/bin/startup.sh

echo 'starting tomcat ...'

/home/shell_scripts/tail-F.sh $tomcat_name 30
"
expect eof
set timeout 30
exit 0

转载于:https://my.oschina.net/yugj/blog/1217779

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值