shell里运行如下
sudo ssh root@192.168.130.131
nohup java -jar /lvnktest/dypay-eureka/dypay-eureka.jar > /lvnktest/dypay-eureka/dypay-eureka.out 2>&1 &
exit
加到jenkins里报错
Pseudo-terminal will not be allocated because stdin is not a terminal.
改成
ssh root@192.168.130.131 "nohup java -jar /lvnktest/dypay-eureka/dypay-eureka.jar > /lvnktest/dypay-eureka/dypay-eureka.out 2>&1 &"
同时添加kill.sh脚本
# cat kill.sh
pid=`ps -ef | grep dypay-eureka.jar | grep -v grep | awk '{print $2}'`
echo $pid
#如果存在则把该进程杀掉
if [ -n "$pid" ]
then
echo "kill -9 的pid:" $pid
kill -9 $pid
fi
BUILD_ID=DONTKILLME
#!/bin/bash
#获取你想运行jar包的进程号
ssh root@192.168.130.131 "/lvnktest/dypay-eureka/start.sh"
echo "复制jar包"
#把jenkins打的jar包复制到自己指定的目录下
sudo scp /var/lib/jenkins/workspace/lvnktest/dypay/dypay-eureka/target/dypay-eureka.jar root@192.168.130.131:/lvnktest/dypay-eureka/
echo "启动jar包"
#最后启动jar包并把日志输出到指定的文件中以便查看
ssh root@192.168.130.131 "nohup java -jar /lvnktest/dypay-eureka/dypay-eureka.jar > /lvnktest/dypay-eureka/dypay-eureka.out 2>&1 &"