我是新来的Jenkins,我想不通如何通过SSH Steps Plugin将文件从一个服务器传输到另一个服务器。你可以展示一些管道的例子吗?将是非常感激的一些帮助!
我已经尝试使用。
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: Auth fail" with working passwords