Created
July 1, 2013 09:39
-
-
Save roidelapluie/5899582 to your computer and use it in GitHub Desktop.
In the jenkins configuration /var/lib/jenkins/config.xml, in the dashboard views, you must pass the jobs in alphabetical order. But if you manipulate the file externally and you alter the jobs list, the jobs that are not in alphabetical order won't appear in the view. This script reorders them.
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/python | |
# This script will re-order the scripts the the jenkins dashboard views | |
# If the jobs are sorted alphabetically, all the jobs do not appear | |
# inside the view. | |
# This script fixes this issues. | |
# USAGE: fix-dashboard-config.py /var/lib/jenkins/config.xml | |
import sys | |
try: | |
from lxml import etree | |
except ImportError: | |
sys.stderr.write("You need lxml to use this script\n") | |
exit(4) | |
if __name__ == '__main__': | |
try: | |
filename = sys.argv[1] | |
except IndexError: | |
sys.stderr.write("You must pass the Jenkins configuration file as argument\n") | |
exit(1) | |
try: | |
doc = etree.parse(filename) | |
except IOError: | |
sys.stderr.write("error accessing the configuration file\n") | |
exit(2) | |
for parent in doc.xpath('//hudson/views/hudson.plugins.view.dashboard.Dashboard/jobNames'): # Search for parent elements | |
children = parent.getchildren() | |
sorted_children = sorted(children,key=lambda x: x.text) | |
parent.clear() | |
for child in sorted_children: | |
parent.append(child) | |
try: | |
doc.write(filename) | |
except IOError: | |
sys.stderr.write("error writing the configuration file\n") | |
exit(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment