简体   繁体   English

如何使用robocopy编写命令行(使用jenkins)压缩一个文件夹?

[英]How to write command line (in jenkins) using robocopy to zip one folder?

How to write command line (in jenkins) using robocopy to zip one folder? 如何使用robocopy编写命令行(使用jenkins)压缩一个文件夹? lets say older then 2 month. 假设年龄大于2个月。

I have jenkins running on windows server (vm), and installed 7zip. 我在Windows服务器(vm)上运行了jenkins,并安装了7zip。

I need to make jenkins run robocopy to archive some folders older then 2 months. 我需要让jenkins运行robocopy来存档一些早于2个月的文件夹。

First of all robocopy is just for copying files. 首先, robocopy仅用于复制文件。 I am assuming you are using Linux Distribution. 我假设您正在使用Linux Distribution。 find . -mtime +60 find . -mtime +60 with this you can list all the files recursively including sub folders which are older than 2 months. find . -mtime +60 ,您可以递归列出所有文件,包括2个月以上的子文件夹。 Or else you can use find . -type d -mtime +60 -maxdepth=1 否则您可以使用find . -type d -mtime +60 -maxdepth=1 find . -type d -mtime +60 -maxdepth=1 to list all the directories only in the current directory. find . -type d -mtime +60 -maxdepth=1以仅列出当前目录中的所有目录。 use -type f for listing all the files. 使用-type f列出所有文件。

This will list all the files and prints on the console. 这将列出所有文件并在控制台上打印。

for i in `find .  -type d -mtime +60 -maxdepth 1`; do echo $i; done

For you, this will do the trick. 对于您来说,这可以解决问题。

for i in `find .  -type d -mtime +60 -maxdepth 1`; do zip -r $i.zip $i; done

In the job config, Have a build step Execute Shell and copy the code and zip folders will be there. 在作业配置中, Execute Shell构建步骤Execute Shell并复制代码和zip文件夹。 Hope this helps. 希望这可以帮助。 If any doubts, Please comment. 如有任何疑问,请发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用正则表达式匹配的文件夹从一台服务器自动复制到另一台服务器 - How to robocopy using regex matched folder from one server to another 使用命令行配置Jenkins - Jenkins configuration using command line 在 Jenkins 中找不到 Zip 命令 - Zip Command not found in Jenkins 如何使用命令行将 Jenkins Slave 设置为作为 Windows 服务运行? - How to setup Jenkins Slave to run as a windows service using command line? 如何在 Jenkins 中使用 MSBuild 命令行覆盖目标文件 - how to overwrite destination file(s) using MSBuild command line in Jenkins 如何使用ubuntu中的命令行在Jenkins中安装插件? - How to install plugins in Jenkins using command line in ubuntu? 将ZIP文件上传到Jenkins中,并在Jenkins中使用Powershell命令提取ZIP文件 - Upload ZIP file into Jenkins and Extract the ZIP file using Powershell command in Jenkins 即使在BAT脚本中成功执行了ROBOCOPY命令,JENKINS作业也会失败 - JENKINS job is failed even if ROBOCOPY command successfully executed in a BAT script 使用Github身份验证连接到Jenkins命令行 - Connecting to Jenkins command line using Github authentication 如何从命令行运行 Jenkins 构建? - How to run a Jenkins Build from Command Line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM