简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM