Skip to content

Instantly share code, notes, and snippets.

@jimklimov
Created April 7, 2025 07:51
Show Gist options
  • Save jimklimov/d4c7dc72dd35918e116713a2109e82fc to your computer and use it in GitHub Desktop.
Save jimklimov/d4c7dc72dd35918e116713a2109e82fc to your computer and use it in GitHub Desktop.
Parsing Jenkins build history for broken XML files with xmllint
# 1) Jenkins uses XML 1.1 standard that did not pick up in the industry after 20 years.
# So browsers and xmllint claim they do not know of it: https://stackoverflow.com/a/4508357
# Jenkins docs suggest replacing with "1.0" should suffice: https://www.jenkins.io/doc/upgrade-guide/2.107/
# 2) changelogNNNNNNNNNN.xml files are not XML but git commit info in fact
# 3) Some of those are plain empty and upset xmllint
# 4) xmllint insists on having an input file, so after rewrites we give it /dev/stdin.
# This path name may be a feature of bash and/or certain platforms.
find . -name '*.xml' | while read F ; do
[ -s "$F" ] || continue;
head -1 "$F" | grep -E '^commit' >/dev/null && continue;
sed 's,xml version=.1.1. encoding=.UTF-8.,xml version="1.0" encoding="UTF-8",' \
< "$F" | xmllint /dev/stdin >/dev/null \
|| echo "FAILED ($?) for $F" ;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment