问题:今天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





Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐