0

I'm new to Jenkins and I can't figure it out how to transfer file from one server to another via SSH Steps Plugin. Can you show some pipeline example? Would be very grateful for some help!

Already I have tried to use:

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
  • Are you referring remote-to-remote file transfer from Jenkins? – saurabh14292 Jun 01 '20 at 17:51
  • My file.zip is on Jenkins server (/var/lib/jenkins/workspace/test-item-xyz/xyz.zip) and I`m trying to transfer it to another Nginx server via SSH Steps Plugin in /var/www/html/ folder. Then I want to unzip it ) – Максим Синюк Jun 02 '20 at 16:02
  • Generally, you configure/define a remote host with IP/Hostname and login credentials and configure the job/pipeline with script to execute as ssh. Since you already have pipeline written, would you post any error logs from Jenkins console to look at? – saurabh14292 Jun 02 '20 at 16:21
  • Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in /var/lib/jenkins/workspace/copy_unzip [Pipeline] { [Pipeline] withCredentials Masking supported pattern matches of $identity or $ or $syniuk [Pipeline] { [Pipeline] stage [Pipeline] { (SSH Transfer) [Pipeline] sshPut Sending a file/directory to ****[52.28.246.156]: from: /var/lib/jenkins/workspace/copy_unzip/docs.zip into: /var/www/html/ Aborted by Maxim – Максим Синюк Jun 02 '20 at 17:04
  • I don't see any error here, it just shows you have "abored" the execution. Also, always post these details by editing the question itself. Output or code is not readable in comments, better to post that as part of question. – saurabh14292 Jun 02 '20 at 18:05
  • Sorry for bothering, I`ve tried to find what kind of mistake it could be and I find that it might be some JRE error?... – Максим Синюк Jun 03 '20 at 10:57

1 Answers1

0

This is related to SSH keys. Your error is because of issues in keys used while doing SSH from Jenkins to target server.

Have a look at "com.jcraft.jsch.JSchException: Auth fail" with working passwords

saurabh14292
  • 1,281
  • 2
  • 10
  • 12
  • Sorry its difficult to understand. My jenkins user can enter to 1.2.3.4 thrue terminal with my pem key. Also I add to credentials my pem key and user. On 1.2.3.4 server I have myUser with .ssh/authorized_keys. So its connects well thrue terminal. But why it doesn`t work with pipeline? – Максим Синюк Jun 03 '20 at 16:37