如何通过SSH步骤插件将文件从一台服务器传输到另一台服务器



我是 Jenkins 的新手,我不知道如何通过 SSH 步骤插件将文件从一台服务器传输到另一台服务器。 你能展示一些管道示例吗? 将非常感谢一些帮助!

我已经尝试使用:

def remote = [:]
remote.name = "Nginx"
remote.host = "1.2.3.4"
remote.allowAnyHosts = true
node {
withCredentials([sshUserPrivateKey(credentialsId: 'Nginx_inst', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'myUser')]) {
remote.user = myUser
remote.identityFile = identity
stage("SSH Transfer") {
sshCommand remote: remote, command: "sudo cp /home/myUser/docs.zip /var/www/html"
//      sshPut remote: remote, from: 'docs.zip', into: '/var/www/html/'
sshCommand remote: remote, command: "sudo unzip -tq /var/www/html/docs.zip"
}
}
}
### But I take an error:
Executing command on ****[1.2.3.4]: sudo cp /home/****/docs.zip /var/www/html sudo: false
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
com.jcraft.jsch.JSchException: USERAUTH fail
at com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:119)
at com.jcraft.jsch.Session.connect(Session.java:470)
..............
Finished: FAILURE

这与SSH密钥有关。您的错误是由于从 Jenkins 到目标服务器执行 SSH 时使用的密钥中的问题。

查看带有工作密码的"com.jcraft.jsch.JSchException:身份验证失败">

相关内容

最新更新