Reputation: 3880
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?
Upvotes: 0
Views: 4905
Reputation: 7880
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.
Upvotes: 2