How can I get a list of installed Jenkins plugins?
I searched the Jenkins Remote Access API document, but it was not found. Should I use Jenkins\' CLI? Is there a d
Jenkins 1.588 (2nd of November, 2014) & 1.647 (4th of February, 2016)
Jenkins > Manage Jenkins
System Information
Plugins
I think these are not good enough answer(s)... many involve a couple of extra under-the-hood steps. Here's how I did it.
sudo apt-get install jq
...because the JSON output needs to be consumed after you call the API.
#!/bin/bash
server_addr = 'jenkins'
server_port = '8080'
curl -s -k "http://${server_addr}:${server_port}/pluginManager/api/json?depth=1" \
| jq '.plugins[]|{shortName, version,longName,url}' -c | sort \
> plugin-list
echo "dude, here's your list: "
cat plugin-list
For Jenkins version 2.125 the following worked.
NOTE: Replace sections that say USERNAME and APIKEY with a valid UserName and APIKey for that corresponding user. The API key for a user is available via Manage Users → Select User → API Key option.
You may have to extend the sleep if your Jenkins installation takes longer to start.
The initiation yum update -y
will upgrade the version as well if you installed Jenkins using yum as well.
#JENKINS AUTO UPDATE SCRIPT link this script into a cron
##############
!/bin/bash
sudo yum update -y
sleep 120
UPDATE_LIST=$( sudo /usr/bin/java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -auth [USERNAME:APIKEY] -s http://localhost:8080/ list-plugins | grep -e ')$' | awk '{ print $1 }' );
if [ ! -z "${UPDATE_LIST}" ]; then
echo Updating Jenkins Plugins: ${UPDATE_LIST};
sudo /usr/bin/java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -auth [USERNAME:APIKEY] -s http://localhost:8080/ install-plugin ${UPDATE_LIST};
sudo /usr/bin/java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -auth [USERNAME:APIKEY] -s http://localhost:8080/ safe-restart;
fi
##############
With curl
and jq
:
curl -s <jenkins_url>/pluginManager/api/json?depth=1 \
| jq -r '.plugins[] | "\(.shortName):\(.version)"' \
| sort
This command gives output in a format used by special Jenkins plugins.txt
file which enables you to pre-install dependencies (e.g. in a docker image):
ace-editor:1.1
ant:1.8
apache-httpcomponents-client-4-api:4.5.5-3.0
Example of a plugins.txt
: https://github.com/hoto/jenkinsfile-examples/blob/master/source/jenkins/usr/share/jenkins/plugins.txt
Another option for Python users:
from jenkinsapi.jenkins import Jenkins
#get the server instance
jenkins_url = 'http://<jenkins-hostname>:<jenkins-port>/jenkins'
server = Jenkins(jenkins_url, username = '<user>', password = '<password>')
#get the installed plugins as list and print the pairs
plugins_dictionary = server.get_plugins().get_plugins_dict()
for key, value in plugins_dictionary.iteritems():
print "Plugin name: %s, version: %s" %(key, value.version)
You can be also interested what updates are available for plugins. For that, you have to merge the data about installed plugins with information about updates available here https://updates.jenkins.io/current/update-center.json .
To parse the downloaded file as a JSON you have to read online the second line (which is huge).