Skip to content

Instantly share code, notes, and snippets.

@amosshapira
Last active February 2, 2017 12:48
Show Gist options
  • Save amosshapira/1453f849744a9d0c4f5f683090b6efdd to your computer and use it in GitHub Desktop.
Save amosshapira/1453f849744a9d0c4f5f683090b6efdd to your computer and use it in GitHub Desktop.
Extract list of current plugins from Jenkins and convert them into a Puppet hash with versions, suitable to feed to "plugin_hash" parameter of "rtyler-jenkins" Puppet class
# aligns the '=>' to be accepted by our puppet-lint. The indentation is very
# specific to our source so will have to be adjusted to other files.
# The "29" in the awk printf is the length of the longest plugin name, so all
# other entries are aligned with it. You can get it using "wc -c <<<(longest-plugin-name)"
java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar \
-s http://localhost list-plugins | \
tr -d '()' | \ # get rid of versions in parenthesis, perhaps available upgrades
sort | \
awk '{ printf " \047%s\047%*s=> {\n version => \047%s\047,\n },\n", $1, 29-length($1), "", $NF }'
# The above haven't listed some of the plugins which were installed on the old Jenkins
# server, I don't know why. Here is an alternative way to find all the plugins which were
# expanded from their archives, under the jenkins 'plugins' directory, execute:
for i in *.[jh]pi
do
j=${i//.[jh]pi}
if [[ -e $j/META-INF/MANIFEST.MF ]]
then
echo -n $j
awk -F: '$1 == "Plugin-Version" { print $2 }' $j/META-INF/MANIFEST.MF
fi
done | \
tr -d '\r' | \ # Get rid of ^M's from MANIFEST.MF
sort | \
awk '{ printf " \047%s\047%*s=> {\n version => \047%s\047\n },\n", $1, 29-length($1), "", $2 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment