7
votes

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?

1
I have the same question, anyone can help?Heinz
Wondering the same. Anyone?Dave

1 Answers

2
votes

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