一、背景:
1、jenkins安装在win上,需要将win上指定目录的文件上传上linux中,然后在linux中执行shell命令
2、在Windows环境通过pscp的命令实现文件上传
二、问题说明
在执行任务构建时发生如下报错:
提示需要手动输入才能连接成功,但是jenkins是非交互的,不能手动输入
22:16:48 Started by upstream project "test" build number 23
22:16:48 originally caused by:
22:16:48 Started by user test
22:16:48 Running as SYSTEM
22:16:48 Building in workspace C:\ProgramData\Jenkins\.jenkins\workspace\test\default
22:16:48 [default] $ cmd /c call C:\Windows\TEMP\jenkins11633612435305521318.bat
22:16:48 开始上传文�?
22:16:48 pscp -l root -pw root@123++ -r "D:\Dev Files\Code\JavaProject\School\Lunwen Project\dist.zip" root@192.168.140.128:/home/app/
22:16:48 The host key is not cached for this server:
22:16:48 192.168.140.128 (port 22)
22:16:48 You have no guarantee that the server is the computer you
22:16:48 think it is.
22:16:48 The server's ssh-ed25519 key fingerprint is:
22:16:48 ssh-ed25519 255 SHA256:FepiLHDoxATcD3toC1U56nqlJ6sRp/qom5S13Hh0HBU
22:16:48 If you trust this host, enter "y" to add the key to PSCP's
22:16:48 cache and carry on connecting.
22:16:48 If you want to carry on connecting just once, without adding
22:16:48 the key to the cache, enter "n".
22:16:48 If you do not trust this host, press Return to abandon the
22:16:48 connection.
22:16:48 Store key in cache? (y/n, Return cancels connection, i for more info) Connection abandoned.
22:16:48 Lost connection
22:16:48 上传文件成功
22:16:48 Build step 'Execute Windows batch command' marked build as failure
22:16:48 Finished: FAILURE
三、解决方案
添加pscp的参数-hostkey指定日志中提示的信息,这样就能构建成功了
pscp -l root -pw 123456 -hostkey SHA256:FepiLHDoxATcD3toC1U56nqlJ6sRp/qom5S13Hh0HBU -r "D:\JavaProject\School\dist.zip" root@192.168.150.110:/home/app/
四、总结
希望此篇文章可以帮到有需要的同学,加油