Jenkins - How to clean / move files under 'builds' directory

丶灬走出姿态 提交于 2019-12-12 03:15:11

问题


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?


回答1:


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

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

delete-job would simply look like that :

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

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



来源:https://stackoverflow.com/questions/39079212/jenkins-how-to-clean-move-files-under-builds-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!