How do I download a file over SSH from a remote server in jenkins?
I am using the Publish Over SSH plugin in Jenkins to transfer files to a remote server from the local machine and execute some commands on the remote server.
But there seems to be no option in this plugin to download files from a remote server to a local one.
Can anyone help how can I achieve this?
+3
source to share
1 answer
From a pipeline perspective, I have this workaround
First download the 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 using scp instruction
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 the sake of brevity, I avoid doing other steps that I change a little what I do But the idea is to do the following steps
- Download the artifact (locally)
- Unpack (locally)
- Create a file with the script I want to execute on the remote server (local)
- Copy the script to the remote server
- Copy unziped artifact to remote server
- Execute script
+1
source to share