Skip to content

Instantly share code, notes, and snippets.

@psftw
Created July 24, 2013 03:58
Show Gist options
  • Save psftw/6067973 to your computer and use it in GitHub Desktop.
Save psftw/6067973 to your computer and use it in GitHub Desktop.
cap jenkins retention policies and identify those without policies at all
from glob import glob
import xml.etree.ElementTree as ET
# fix bad retention policies
maxkeep = 20
maxakeep = 20
nopolicy = []
for cfile in glob("jobs/*/config.xml"):
tree = ET.parse(cfile)
root = tree.getroot()
lr = root.find('logRotator')
if lr is None:
nopolicy.append(cfile)
continue
numToKeep = lr.find('numToKeep')
keep = int(numToKeep.text)
aNumToKeep = lr.find('artifactNumToKeep')
akeep = int(aNumToKeep.text)
if keep == -1 or keep > maxkeep:
print "changing keep %3s to %3s: %s" % (keep, maxkeep, cfile)
lr.find('numToKeep').text = str(maxkeep)
if akeep == -1 or akeep > maxakeep:
print "changing akeep %3s to %3s: %s" % (akeep, maxakeep, cfile)
lr.find('artifactNumToKeep').text = str(maxakeep)
tree.write(cfile)
for item in nopolicy:
print "no policy: %s" % item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment