「Jenkins Pipeline」- 文件、目录操作(复制、删除、重命名)

  CREATED BY JENKINSBOT

问题概述

在 Jenkins Pipeline 中,我们经常需要对文件、目录进行操作,比如移动、复制、重命名等等。

该笔记将介绍:在 Jenkins Pipeline 中,常用的目录、文件操作方法。

解决方法

第一步、安装插件

安装 File Operations Plugin 插件

创建目录

fileOperations([folderCreateOperation('directoryname')])

复制文件或者目录

# 在 Jenkinsfile 中
fileOperations {
	folderCopyOperation("/path/to/src", "/path/to/dest")
}

# 在共享库中
fileOperations ([
	folderCopyOperation(sourceFolderPath: "/path/to/src", destinationFolderPath: "/path/to/dest"),
	folderCopyOperation(sourceFolderPath: "/path/to/foo", destinationFolderPath: "/path/to/bar")
])

参考文献

File Operations Plugin
Jenkins pipeline create directory – Stack Overflow