Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to copy files from a directory outside the workspace to workspace in Jenkins pipeline

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.

like image 324
Alberto Jiménez Avatar asked Dec 24 '17 15:12

Alberto Jiménez


2 Answers

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

like image 103
Alberto Jiménez Avatar answered Nov 15 '22 09:11

Alberto Jiménez


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}'
like image 30
Karanva Avatar answered Nov 15 '22 07:11

Karanva