Created
August 7, 2013 02:56
-
-
Save dctrwatson/6170797 to your computer and use it in GitHub Desktop.
Update jenkins matrix build with config per python app
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
import os | |
import re | |
import urllib | |
from lxml import etree | |
JENKINS_CONIG_URL = 'http://jenkins.local/job/integration-tests/config.xml' | |
BLACKLIST = set(('tests/integration/app1', 'tests/integration/app2', )) | |
def remove_root_from(path): | |
root = folder() + os.sep | |
return path.replace(root, '') | |
def folder(*folders): | |
root = os.path.abspath( | |
os.path.join(os.path.dirname(__file__), os.pardir) | |
) | |
return os.path.join(root, *folders) | |
def directories_in(*folders): | |
fold = folder(*folders) | |
for item in os.listdir(fold): | |
full_path = os.path.join(fold, item) | |
if os.path.isdir(full_path): | |
yield full_path | |
apps = set(directories_in('tests', 'integration')) | |
# Strip the leading folder path from all the apps | |
apps = set(map(remove_root_from, apps)) | |
# Remove any elements on the blacklist | |
apps = apps - BLACKLIST | |
# Pull down XML | |
root = etree.parse(urllib.urlopen(JENKINS_CONIG_URL)) | |
values_element = root.xpath('//axes/hudson.matrix.TextAxis/values')[0] | |
print 'Updating integration-tests app matrix config' | |
print '-' * 80 | |
# Remove the old apps | |
for element in list(values_element): | |
print '-', element.text | |
values_element.remove(element) | |
# Add the new apps | |
for app in apps: | |
print '+', app | |
sub = etree.SubElement(values_element, "string") | |
sub.text = app | |
# Post the new XML back to Jenkins | |
new_xml = etree.tostring(root.getroot()) | |
urllib.urlopen(JENKINS_CONIG_URL, data=new_xml) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment