Skip to content

Instantly share code, notes, and snippets.

@jollychang
Created March 28, 2013 05:46

Revisions

  1. jollychang created this gist Mar 28, 2013.
    21 changes: 21 additions & 0 deletions clean_jenkins_workspace.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/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)