Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download file over SSH from remote server in jenkins?

I am using Publish Over SSH plugin in Jenkins to transfer the files over to remote server from local and execute some commands on the remote server.

But, it seems like there is no option available in this plugin to download files from remote server to local.

Can some one assist how can i achieve this?

like image 312
Karthick Avatar asked May 31 '17 05:05

Karthick


People also ask

How to download files from remote system over SSH protocol?

Here are some useful examples for downloading files from the remote system over SSH protocol. This will connect to example.com server with user “ username ” and copy the /backup/file.zip file to local system directory /local/dir. To use theis command replace the values as per your environment.

How do I connect to a remote server using SSH?

If your remote server required the private key to connect server, You can use -i followed by private key file path to connect your server using the SCP command. This can be helpful for AWS servers. Upload file using SSH. You can also upload files to the remote server using SSH protocol using SCP command.

What is OpenSSH ssh?

Linux and OS X systems: OpenSSH SSH/SecSH protocol suite (which comes pre-installed with OS X and available for download for most other *nix systems) includes the scp (secure copy) application which can be used to upload and download files from and to remote hosts.

Can I download a file from SSH to my local desktop?

However, sometimes you will need to download a file from SSH to your local desktop, such as if you are using one of our Linux VPS servers. And there’s no simple command from within the SSH terminal itself to do this. The two environments are too far apart.


1 Answers

From a pipeline perspective I have this workaround

First download in you Jenkins server instance

stage("Download") {
  steps {
    fileOperations([fileDownloadOperation(password: "", targetFileName: "${params.APP_KEY}.zip", targetLocation: "${params.HOME_PATH}", url: "${params.ARTIFACT_URL}", userName: "")])
  }
}

and then copy with a scp instrucction

stage("Download last version") {
  sshagent(['xxxx-xxxx-xxxx-xxxx-xxxx']) {
    sh "scp ${params.APP_KEY_PATH}/${params.APP_KEY}.ZIP ${params.REMOTE_SERVER_USER}@${params.REMOTE_SERVER_URL}:${params.REMOTE_APP_KEY_PATH}"
  }
}

For brevity I am avoiding to put another steps that I change a little bit what I do But the idea is to do the following steps

  1. Download the artifact (locally)
  2. Unzip (locally)
  3. Create a file with the script I want to execute in the remote server (locally)
  4. Copy the script to the remote server
  5. Copy the unziped artifact to the remote server
  6. Execute the script
like image 126
agusgambina Avatar answered Nov 07 '22 11:11

agusgambina