Skip to content

Instantly share code, notes, and snippets.

@jollychang
Created March 28, 2013 05:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jollychang/5260975 to your computer and use it in GitHub Desktop.
Save jollychang/5260975 to your computer and use it in GitHub Desktop.
clean jenkins master and slave workspace( fix https://issues.jenkins-ci.org/browse/JENKINS-2111 )
#!/usr/bin/env python
#-*-coding:utf-8-*-
import urllib, json , os
from shutil import rmtree
url = 'http:/yourjenkinsbaseurl/api/python?pretty=true'
jenkins_workspace_path = '/data/jenkins/workspace/'
data = eval(urllib.urlopen(url).read())
jobnames = []
for job in data['jobs']:
jobnames.append(job['name'])
ws = os.listdir(jenkins_workspace_path)
for workspace in ws:
if workspace not in jobnames:
workspace_path = os.path.join(jenkins_workspace_path, workspace)
print "remove dir: %s " % workspace_path
rmtree(workspace_path)
@AaronDMarasco-VSI
Copy link

FYI, this doesn't work with the Cloudbees folder plugin. Or the api/python URL doesn't. See https://gist.github.com/jhoblitt/5f812cba39f0ec3c2e01f00d97d379a2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment