如何从终端更新jenkins插件?

如何从终端更新jenkins插件?

问题描述:

我正在尝试创建一个Bash脚本来设置Jenkins.有什么方法可以从Jenkins终端更新插件列表吗?

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

即:

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

不起作用

一种简单但可行的方法是首先列出所有已安装的插件,查找更新并进行安装.

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

每个具有更新的插件,其最新版本都在括号中.因此,您可以为这些设置grep:

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 }'

如果使用插件名称调用install-plugin,它将自动升级到最新版本.

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

最后,您必须重新启动詹金斯.

Finally you have to restart jenkins.

将它们放在一起(可以放置在shell脚本中):

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