如何从终端更新 jenkins 插件?
我正在尝试创建一个 bash 脚本来设置 Jenkins。有没有办法从 Jenkins 终端更新插件列表?
第一次设置时,列表中没有可用的插件,
即:
java -jar jenkins-cli.jar -s `http://localhost:8080` install-plugin dry
无法工作
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
一个简单但有效的方法是首先列出所有已安装的插件,查找更新并安装它们。
java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins
每个有可用更新的插件都会在末尾的括号中显示新版本。因此,您可以 grep 查找这些:
java -jar /root/jenkins-cli.jar -s http://127.0.0.1:8080/ list-plugins | grep -e ')$'| awk '{ print $1 }'
如果您使用插件名称调用 install-plugin,它会自动升级到最新版本。
最后你必须重新启动詹金斯。
将它们放在一起(可以放在 shell 脚本中):
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):
您实际上可以从计算机终端(而不是 Jenkins 终端)安装插件。
http://updates.jenkins-ci.org/download/plugins
) 下载插件,$JENKINS_HOME/plugins
目录http://yourservername:8080/jenkins/reload
)这将在 Jenkins 中启用插件并假设 Jenkins 已启动。
You can actually install plugins from the computer terminal (rather than the Jenkins terminal).
http://updates.jenkins-ci.org/download/plugins
)$JENKINS_HOME/plugins
directoryhttp://yourservername:8080/jenkins/reload
)This will enable the plugin in Jenkins and assuming that Jenkins is started.
以下是如何使用 Ansible 部署 Jenkins CI 插件,当然这是从终端使用的。此代码是
roles/jenkins_ci/tasks/main.yaml
的一部分:这是更完整示例的一部分,您可以在以下位置找到该示例:
https://github.com/sakaal/service_platform_ansible/ blob/master/roles/jenkins_ci/tasks/main.yaml
请随意调整它以满足您的需求。
Here is how you can deploy Jenkins CI plugins using Ansible, which of course is used from the terminal. This code is a part of
roles/jenkins_ci/tasks/main.yaml
:This is a part of a more complete example that you can find at:
https://github.com/sakaal/service_platform_ansible/blob/master/roles/jenkins_ci/tasks/main.yaml
Feel free to adapt it to your needs.
您可以使用此命令行更新插件列表
You can update plugins list with this command line
仅供参考 - 某些插件(特别是 Mercurial)无法从命令行正确安装,除非您使用它们的短名称。我认为这与詹金斯包信息数据中的触发器有关。您可以通过在支持 javascript 的浏览器中访问
127.0.0.1:8080/pluginManager/checkUpdates
来模拟 jenkins 自己的包更新。或者,如果你感觉受虐狂,你可以运行这个 python 代码:
一旦你运行了这个,你应该能够运行 jenkins-cli -s http://127.0.0.1:8080 install-plugin Mercurial -部署。
FYI -- some plugins (mercurial in particular) don't install correctly from the command line unless you use their short name. I think this has to do with triggers in the jenkins package info data. You can simulate jenkins' own package update by visiting
127.0.0.1:8080/pluginManager/checkUpdates
in a javascript-capable browser.Or if you're feeling masochistic you can run this python code:
And once you've run this, you should be able to run
jenkins-cli -s http://127.0.0.1:8080 install-plugin mercurial -deploy
.在当前的 Jenkins 版本中,CLI 只能通过 SSH 使用。必须在管理界面的“全局安全设置”页面中启用此功能,如 文档。此外,应触发更新的用户必须添加其公共 ssh 密钥。
使用已接受答案中修改后的 shell 脚本,可以如下自动化,您只需替换 HOSTNAME 和 USERNAME:
这将 greps Jenkins CLI 的已使用 SSH 端口,然后通过 SSH 连接,而无需检查主机密钥,因为它发生了变化每次 Jenkins 重新启动时。
然后所有有可用更新的插件都会升级,然后 Jenkins 会重新启动。
With a current Jenkins Version, the CLI can just be used via SSH. This has to be enabled in the "Global Security Settings" page in the administration interface, as described in the docs. Furthermore, the user who should trigger the updates must add its public ssh key.
With the modified shell script from the accepted answer, this can be automatized as follows, you just have to replace HOSTNAME and USERNAME:
This greps the used SSH port of the Jenkins CLI and then connects via SSH without checking the host key, as it changes for every Jenkins restart.
Then all plugins with an update available are upgraded and afterwards Jenkins is restarted.
在 groovy 中
groovy 路径有一个很大的优点:它可以添加到作业中的“系统 groovy 脚本”构建步骤中,而无需进行任何更改。
使用以下内容创建文件“update_plugins.groovy”:
然后执行以下curl命令:
In groovy
The groovy path has one big advantage: it can be added to a 'system groovy script' build step in a job without any change.
Create the file 'update_plugins.groovy' with this content:
Then execute this curl command: