Forked from timp21337/clean_jenkins_workspace.py
Last active
August 29, 2015 14:24
-
-
Save alexmerser/bd5111b2729cbde05da8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 = '/var/lib/jenkins/workspaces/' | |
| 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment