如何将文件从工作区外部的目录复制到Jenkins管道中的工作区 [英] how to copy files from a directory outside the workspace to workspace in Jenkins pipeline

查看:397
本文介绍了如何将文件从工作区外部的目录复制到Jenkins管道中的工作区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Jenkins管道开始,我想将某些视频文件从任何jenkins目录之外复制到我的工作区目录中.我正在使用文件操作插件为我拥有的其他作业执行一些文件操作.使用该插件,我可以将文件从工作区内部复制到外部:

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")])

例如,通过此步骤,我可以将工作区中的4个视频文件复制到另一个磁盘中提到的目录中.

With this step, for example, I can copy 4 video files located in my workspace to the mentioned directory, located in another disk.

但是我想相反.我想将视频文件从另一个磁盘中的源目录复制到工作区.我用几种方法尝试过,但是' includes '字段似乎不接受绝对路径.例如:

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:

文件复制操作: 致命:期望使用Ant GLOB模式,但看到"H:\ home \ Videos \ videos \ *.MTS".请参见 http://ant.apache.org/manual/Types/fileset.html语法

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.

推荐答案

实际上,问题似乎不是从工作空间外部而是从当前工作目录外部复制文件.我仍然不知道该怎么做.

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}")])
}

此代码使您可以复制放置在工作区目录中提到的目录中的mts文件.您可以在 dir 步骤此处

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

这篇关于如何将文件从工作区外部的目录复制到Jenkins管道中的工作区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆