Skip to content

Instantly share code, notes, and snippets.

@timcrider
Created November 16, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timcrider/9e6c31e96fe6ec1f6ebc7c296eeec1d3 to your computer and use it in GitHub Desktop.
Save timcrider/9e6c31e96fe6ec1f6ebc7c296eeec1d3 to your computer and use it in GitHub Desktop.
Shell script to export Jenkins plugins/versions into an ansible friendly format
#!/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