How can I update jenkins plugins from the terminal?

anilyeni picture anilyeni · Oct 10, 2011 · Viewed 41.9k times · Source

I am trying to create a bash script for setting up Jenkins. Is there any way to update a plugin list from the Jenkins terminal?

At first setup there is no plugin available on the list

i.e.:

java -jar jenkins-cli.jar -s `http://localhost:8080` install-plugin dry

won't work

Answer

Michael Wyraz picture Michael Wyraz · Sep 3, 2014

A simple but working way is first to list all installed plugins, look for updates and install them.

java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins

Each plugin which has an update available, has the new version in brackets at the end. So you can grep for those:

java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins | grep -e ')$' | awk '{ print $1 }'

If you call install-plugin with the plugin name, it is automatically upgraded to the latest version.

Finally you have to restart jenkins.

Putting it all together (can be placed in a shell script):

UPDATE_LIST=$( java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins | grep -e ')$' | awk '{ print $1 }' ); 
if [ ! -z "${UPDATE_LIST}" ]; then 
    echo Updating Jenkins Plugins: ${UPDATE_LIST}; 
    java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ install-plugin ${UPDATE_LIST};
    java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ safe-restart;
fi