Recommnended approach for jenkins housekeeping

585 views
Skip to first unread message

ok999

unread,
Feb 11, 2016, 12:06:40 AM2/11/16
to Jenkins Users

A job/pipeline is using custom workspace. The job is set-up in such a way that every build creates there own workspace inside the main/default workspace. So, if the actual workspace is "D:\jenkins\workspace\<job_name>", each run of the job/pipeline is creating there own workspace like

"D:\jenkins\workspace\<job_name>\1"
"D:\jenkins\workspace\<job_name>\2"
"D:\jenkins\workspace\<job_name>\3"

.
.
.
This lock down of workspace is implemented as per a requirement.

If the job is successful, these workspaces are deleted in a stage using the deletedir(). But if the job fails, i leave them for postmortem.

Is there any standard/recommended way to clean up the entire workspace in a scheduled way (like once a month)? I have a pool of slaves and the scheduled job should clean in all slaves.

Victor Martinez

unread,
Feb 11, 2016, 3:43:29 AM2/11/16
to Jenkins Users
Hi,

I don't know if there is already a specific plugin for doing that, the closest feature afaik is already implemented by https://wiki.jenkins-ci.org/display/JENKINS/Maintenance+Jobs+Scheduler+Plugin which will cronly remove/disable jobs older than X days.

It would be easy to adapt it to cleanup workspaces older than one month or so.

Otherwise you might need to create your own groovy script to iterate through each slave/job and filter workpsaces older than X days then wipe them out.

Cheers

ok999

unread,
Feb 11, 2016, 10:31:41 PM2/11/16
to Jenkins Users
Thanks Victor for your suggestion. I also came accross this http://stackoverflow.com/questions/28488389/jenkins-how-to-run-one-housekeeping-job-on-all-nodes-slaves-master 

I haven't tried it yet, but i will be looking into the plugin in this SO post. I will update back


Regards!
Reply all
Reply to author
Forward
0 new messages