解决:ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [-1]]

问题:今天Jenkins使用Publish Over SSH Plugin遇到一个问题:错误如下

SSH: Connecting from host [localhost.localdomain]
SSH: Connecting with configuration [47.94.8.78] ...
SSH: EXEC: STDOUT/STDERR from command [rm -rf /var/tmp/garage/server/center
unzip -oq /var/tmp/remote-deploy/garage-dacheng-server.war -d /var/tmp/garage/server/center
ps -ef |grep tomcat-center |awk '{print $2}'|xargs kill -9  1>/dev/null 2>&1 | exit 0
service tomcat-center start] ...
SSH: EXEC: completed after 1,007 ms
SSH: Disconnecting configuration [47.94.8.78] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [-1]]
Build step 'Send build artifacts over SSH' changed build result to UNSTABLE
Finished: UNSTABLE
“Exec exit status not zero” 说明进程没有正常结束,经过排除,问题锁定在:
ps -ef |grep tomcat-center |awk '{print $2}'|xargs kill -9  1>/dev/null 2>&1 | exit 0

分析:

ps -ef | grep tomcat-center 查询到的是两条记录(如下图):第一条是我们要查找并关闭的,第二条是查找进程自身。

当管道进行到kill的时候,两条进程一同被杀死,而Jenkins仍然在等待查找进程自身返回exit 0,事实上它永远等不到了,因为进程都没了,

最终会报异常"Exec exit status not zero"

解决:

使用“grep -v grep”排除掉它自身就可以

原来:ps -ef |grep tomcat-center |awk '{print $2}'|xargs kill -9

改后:ps -ef |grep tomcat-center | grep -v grep |awk '{print $2}'|xargs kill -9





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值