Created
November 16, 2018 15:32
-
-
Save timcrider/9e6c31e96fe6ec1f6ebc7c296eeec1d3 to your computer and use it in GitHub Desktop.
Shell script to export Jenkins plugins/versions into an ansible friendly format
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
#!/bin/bash | |
# Requirements | |
PROGS=("xmlstarlet") | |
for PROG in "${PROGS[@]}" ; do | |
command -v $PROG >/dev/null 2>&1 || { echo >&2 "System requirement $PROG not met. Please install $PROG"; exit 1; } | |
done | |
# Sanity | |
if [[ "$1" == "" ]] ; then | |
JENKINS_PLUGIN_DIR="/var/lib/jenkins/plugins" | |
else | |
JENKINS_PLUGIN_DIR="$1" | |
fi | |
if [ ! -d $JENKINS_PLUGIN_DIR ] ; then | |
echo "Jenkins plugin directory is not a directory: ${JENKINS_PLUGIN_DIR}" | |
exit 1 | |
fi | |
SPACES=$(printf "%0.s " {1..2}) | |
# Process | |
echo "initial:" | |
for LIC in `ls -1 $JENKINS_PLUGIN_DIR/*/WEB-INF/licenses.xml` ; do | |
ART_ID=$(cat "${LIC}" | xmlstarlet sel -t -v '/l:dependencies/@artifactId') | |
VER_ID=$(cat "${LIC}" | xmlstarlet sel -t -v '/l:dependencies/@version') | |
printf '%s- name: "%s"\n' "${SPACES}" "${ART_ID}" | |
printf '%s version: "%s"\n' "${SPACES}" "${VER_ID}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment