Jenkins-如何在' builds'下清理/移动文件目录 [英] Jenkins - How to clean / move files under 'builds' directory

查看:55
本文介绍了Jenkins-如何在' builds'下清理/移动文件目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Jenkins与Pipeline脚本一起使用.在脚本末尾,我要删除/移动 Jenkins \ jobs \ MyMultiBranch \ branches \ master \ builds 的某些内容(即一些日志和build.xml)

I am using Jenkins with Pipeline script. At the end of the script I want to delete/move some contents of Jenkins\jobs\MyMultiBranch\branches\master\builds (i.e. some logs and build.xml)

如何使用管道来完成?我尝试过了

How can it be done using Pipeline? I tried this;

bat "del /F \"C:\\Program Files (x86)\\Jenkins\\jobs\\MyMultiBranch\\branches\\master\\builds\\%BUILD_NUMBER%\\build.xml\""

但是它不起作用,文件仍然存在.有人可以帮忙吗?

but it's not working, the files are still there. Can anyone help?

推荐答案

Jenkins无法删除其自己的工作目录确实很有意义.我猜您可以做的是先保存要保存的工件,如丹尼尔提到的那样,然后触发第二个作业(例如 delete-job ),该作业将负责清理您的作业A 工作区.看起来像这样:

It does make sense that Jenkins would not be able to delete its own working directory. I guess what you could do is first save artifacts you want to save as Daniel mentionned and then trigger a second job (say delete-job) that will be responsible for cleaning your job A workspace. It would look like this :

// First save out anything you want
archiveArtifacts artifacts: '**/saveme.log'

// At the very end of your pipeline, call delete-job with the path you want to delete as a build parameter
build job: 'delete-job', quietPeriod: 5, wait: false, parameters: [[$class: 'StringParameterValue', name: 'folderToDelete', value: "${pathToFolderToDelete}"]]

安静期应该足以使delete-job删除您的 job A 文件夹.

The quiet period should be enough for the delete-job to be able to delete your job A folder.

删除工作就像这样:

node() {
  bat "del /F '${pathToFolderToDelete}'"
}

pathToFolderToDelete 是Jenkins根据作业参数自动推断出的变量.

Where pathToFolderToDelete is a variable automatically infered by Jenkins based on the job parameters.

这篇关于Jenkins-如何在' builds'下清理/移动文件目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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