Question
· Jan 27, 2019

Move files from server into Jenkins workspace.

Hello,

I am trying to copy an xml file generated on an Apache server into the Jenkins workspace post-build. I was thinking to use a 'send files over ssh' post-build script, but have not done this before and do not know how to refer to the file location on Apache server vs on Jenkins.

For example, if I want to copy from Apache's location of: "classes/UnitTest/Results.xml" into Jenkin's workspace: "/ReportFiles/Results.xml",

How does the script differentiate between whether the location address refers to the Apache server or Jenkins workspace?

Or is there a better alternative way to do this?
 

Discussion (2)0
Log in or sign up to continue

The post build script executes on the node that the Jenkins build ran on.  Therefore, that node machine is “local” for the purposes of copying remote files, and the machine where the XML file you want to copy lives is the “remote” machine.

You’ve probably seen this, but here’s the documentation for the Secure Copy Protocol (scp) command:

https://linuxize.com/post/how-to-use-scp-command-to-securely-transfer-files/

The relevant form for you should be:

scp user@hostOfFileToCopy:/path/to/fileToCopy /path/to/newCopy

“user” needs to be the name of a user who has permissions to copy the file. hostOfFileToCopy identifies the machine on which that XML file lives (could be an IP address). /path/to/fileToCopy is the absolute path, on that machine, of the file you want to copy.

/path/to/newCopy is the absolute path for the destination of the copy on the machine the Jenkins build is running on, not just the relative path from within the Jenkins workspace.  For example, while your path within the Jenkins workspace might be “/ReportFiles/Results.xml", the absolute path on the machine is probably something like “/Jenkins/workspace/ReportFiles/Results.xml”

Hope this helps.