1、端口问题造成的连接失败
remote-prepare: [sshexec] Connecting to 123.123.123.123:22 java.net.ConnectException: Connection timed out
解决办法
修改build.xml,配置端口号
<target name="remote-prepare"> <sshexec host="${web.host}" username="${web.host.user}" port="2014" password="${web.host.pwd}" command="mkdir -p ${web.host.webroot}/../builds" trust="true" /> </target>
2、显示无权限
com.jcraft.jsch.JSchException: Auth fail
原因:为了安全起见,服务器连接不是使用用户名密码方式,而是使用秘钥文件,所以需要把password换成keyfile
<target name="remote-prepare"> <sshexec host="${web.host}" username="${web.host.user}" port="2014" keyfile="${web.host.pwd}" command="mkdir -p ${web.host.webroot}/../builds" trust="true" /> </target>
端口号和keyfile标签的修改需要记得把所有用到的地方都改掉,避免遗漏
3、显示没有提供密码或者密码短语
neither password nor passphrase for user root has been given. Can‘t authenticate.
添加passphrase
<target name="upload" depends="package" unless="noup"> <fail unless="web.host.webroot" message="Please specify ${web.host.webroot}. eg, -Dwebroot.dir=/var/www/htdocs/" /> <antcall target="remote-prepare" /> <echo>Uploading build tar file to ${web.host.webroot}/../builds</echo> <echo>This will take a few minutes...</echo> <scp file="${build.file}" verbose="true" todir="${web.host.user}@${web.host}:${web.host.webroot}/../builds" passphrase="" port="2016" keyfile="${web.host.pwd}" trust="true" /> </target>
使用hudson时遇到的ssh上传问题,布布扣,bubuko.com
原文:http://my.oschina.net/u/173975/blog/298311