How can I update jenkins plugins from the terminal?

后端 未结 6 2021
庸人自扰
庸人自扰 2021-01-30 11:07

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 availab

6条回答
  •  情书的邮戳
    2021-01-30 11:38

    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
    

提交回复
热议问题