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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With