Jenkins SSH PUBLISHER报错:Exception when publishing, exception message [Exec exit status not zero. Status [1]]Status [-1]Status [255]…
status[1] 一般是命令本身报错了,但是有时候是环境变量的问题,具体情况很难找到,其实只要打开verbose日志输出,就很容易找到原因。
打开SSH插件的verbose output in console
jenkins job的配置中SSH Publishers插件的高级选项,选中
“verbose output in console”,这样会显示详细的SSH输出,就能够很直观的看到原因。
根据原因再查找解决方法。
查看日志
SSH: Creating session: username [root], hostname [10.199.157.153], port [22]
SSH: Connecting session ...
channel stopped
SSH: Connected
SSH: Opening SFTP channel ...
SSH: SFTP channel open
SSH: Connecting SFTP channel ...
SSH: Connected
SSH: cd [/]
SSH: OK
SSH: cd [/]
SSH: OK
SSH: cd [tomcat/tomcat8030]
SSH: OK
SSH: put [tdap-meta-service.war]
SSH: OK
SSH: Opening exec channel ...
SSH: EXEC: channel open
SSH: EXEC: STDOUT/STDERR from command [cd /tomcat/tomcat8030/webapps
../bin/catalina.sh stop
../bin/startup.sh] ...
SSH: EXEC: connected
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
SSH: EXEC: completed after 203 ms
可以比较清晰的看到是JAVA_HOME没有设置,通过SSH执行的命令,是读取不到设置在/etc/profile里面的JAVA_HOME的配置的。
需要显式的export JAVA_HOME="/usr/local/jdk_home";