Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sboardwell/4bdf0eef63ddad844c7b3d6b8f067b6e to your computer and use it in GitHub Desktop.
Save sboardwell/4bdf0eef63ddad844c7b3d6b8f067b6e to your computer and use it in GitHub Desktop.
list-jenkins-plugins
#!/usr/bin/env bash
# Script to get a list of plugins from a Jenkins server
set -euo pipefail
# set the necessary vars
JENKINS_URL=${JENKINS_URL:-http://localhost:8080}
JENKINS_USER=${JENKINS_USER:-admin}
JENKINS_TOKEN=${JENKINS_TOKEN} # eg. abcd1234abcd1234abcd1234
JENKINS_CRUMB=$(curl --silent -u ${JENKINS_USER}:${JENKINS_TOKEN} "${JENKINS_URL}/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
# get a list of the plugins to, for example, put into the plugins.txt
THE_SCRIPT='script=Jenkins.instance.pluginManager.plugins.stream().sorted().collect(java.util.stream.Collectors.toList()).each{ plugin -> println ("${plugin.getShortName()}:${plugin.getVersion()}") };x=""'
echo "${THE_SCRIPT}" | curl -u $JENKINS_USER:$JENKINS_TOKEN -H $JENKINS_CRUMB --netrc --silent --data-binary @- -X POST "$JENKINS_URL/scriptText" | grep -vE "^Result:" > plugins.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment