本文介绍了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无法删除其自己的工作目录确实很有意义.我猜您可以做的是首先保存要保存的工件,如Daniel所述,然后触发第二项工作(例如delete-job),该工作将负责清理您的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.

delete-job看起来就像这样:

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

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

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

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

10-23 01:26