Created
July 24, 2013 03:58
-
-
Save psftw/6067973 to your computer and use it in GitHub Desktop.
cap jenkins retention policies and identify those without policies at all
This file contains 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
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