问题
I'm starting with Jenkins pipelines, and I want to copy some video files from outside any jenkins directory to my job workspace directory. I'm using the File Operations Plugin to perform some file operations for other jobs I have. With that plugin, I'm able to copy files from inside my workspace to outside:
fileOperations([fileCopyOperation(excludes: '', flattenFiles: false, includes: "videos\\*.MTS", targetLocation: "H:\\home\\Videos")])
With this step, for example, I can copy 4 video files located in my workspace to the mentioned directory, located in another disk.
But I want to do the opposite. I want to copy video files from a source directory in the other disk to the workspace. I tried it in several ways, but seems that 'includes' field doesn't accept absolute paths. For example:
fileOperations([fileCopyOperation(excludes: '', flattenFiles: false, includes: "H:\\home\\Videos\\videos\\*.MTS", targetLocation: ".")])
This returned the following error in the console output:
File Copy Operation: FATAL: Expecting Ant GLOB pattern, but saw 'H:\home\Videos\videos\*.MTS'. See http://ant.apache.org/manual/Types/fileset.html for syntax
So, i'm stuck trying to carry some files to the workspace directory in order to be processed there.
Note: I'm using a declarative pipeline for my job.
回答1:
In fact, seems that the problem is not copying files from outside the workspace but from outside the current working dir. I still don't know how to do this.
But, you can change the current working dir to be the one that contains files you want to copy, so:
dir("H:\\home\\Videos\\videos") {
fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: '*.MTS', targetLocation: "${WORKSPACE}")])
}
This code allows you to copy mts files placed in the mentioned directory in the workspace dir. You can see additional help for the dir step here
回答2:
When I tried the accepted answer, I stopped getting the error but the file was not copied to my workspace and since there was no error, I got no information as to why.
Anyway what worked for me was to just run a 'powershell' step and use the command 'copy' since I'm working on Windows, and if you are in Linux you can use the step 'sh' instead.
e.g.
powershell 'copy "${source}" ${filename}'
来源:https://stackoverflow.com/questions/47961806/how-to-copy-files-from-a-directory-outside-the-workspace-to-workspace-in-jenkins