How can I delete files in directory using jenkins

你说的曾经没有我的故事 提交于 2020-08-10 05:29:06

问题


In my system, I am downloading new build everyday in 1 folder and then use it for further causes but after running jenkins job I want to delete files in the folder (not workspace) which will delete specific folders from same directory. This will help me downloading new build every time based on different jenkins job running on same machine.

EG:

I am downloading x.x build and then running jenkins job on machine and then if I want to run other job which requires x.y build, it will just see if SOME build is already there in folder. if it is there, it will not download any kit after that. So, now simplest thing I can do is delete x.x after every jenkins run (post build ) so it will download x.y next time..

Please help. Thanks in advance


回答1:


You can delete the whole folder using this syntax to delete a folder called bin:

stage('Setup') {
    steps {
        dir ('bin') {
            deleteDir()
        }
    }
}



回答2:


If my understanding is right, consider my below assumptions

If your jenkins is running on a Unix server, then you can configure a post build step as suggested by nerdwaller above

  1. In the job configuration, in the build step, select the option "execute unix command"
  2. In the box for the shell script, you can use rm -rf <<directoryname>>

Else, if your jenkins is running on a windows server, then select "execute batch command" from the build step and give the appropriate command like rmdir /Q /S nonemptydir

However, my best approach would be to use a platform independent tool like ant to delete the folders using Ant Delete Task and it can be configured similarly like the above two approaches instead selecting "invoke ant" in the build step/ post build step.

This will help you to achieve what you need.



来源:https://stackoverflow.com/questions/26921334/how-can-i-delete-files-in-directory-using-jenkins

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