-
-
Save abayer/8bd1044ed63ac55ed3fcb7ba23a642d1 to your computer and use it in GitHub Desktop.
A simple script to update a pom.xml for the latest updates
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/env bash | |
DEPENDS=$(xmlstarlet sel -N x='http://maven.apache.org/POM/4.0.0' \ | |
-t -m x:project/x:dependencies/x:dependency \ | |
-v x:artifactId -o ' ' \ | |
pom.xml) | |
if [ ! -f update-center.actual.json ]; then | |
wget https://updates.jenkins.io/update-center.actual.json; | |
fi; | |
NEWEST_CORE=2.7.3 | |
for d in $DEPENDS; do | |
VERSION=$(jq -r ".plugins[\"${d}\"].version" < update-center.actual.json) | |
echo "> ${d} should be ${VERSION}" | |
DEPEND_CORE=$(jq -r ".plugins[\"${d}\"].requiredCore" < update-center.actual.json) | |
if python -c "from distutils.version import StrictVersion; import sys; sys.exit(0 if StrictVersion('"${DEPEND_CORE}"') > StrictVersion('"${NEWEST_CORE}"') else 1)"; then | |
NEWEST_CORE=${DEPEND_CORE} | |
echo "New core: ${NEWEST_CORE}" | |
fi | |
# Thanksk to this post for enough pointers | |
# https://stackoverflow.com/questions/51785967/xmlstarlet-select-and-update-xml | |
xmlstarlet ed \ | |
--ps --inplace \ | |
-N x='http://maven.apache.org/POM/4.0.0' \ | |
-u "//x:artifactId[.='${d}']/following-sibling::x:version[1]" \ | |
-v ${VERSION} \ | |
pom.xml | |
done; | |
echo "Updating jenkins.version to ${NEWEST_CORE}" | |
sed -i '' "s/<jenkins\.version>.*<\/jenkins.version>/<jenkins.version>$NEWEST_CORE<\/jenkins.version>/" pom.xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment