Last active
October 11, 2024 13:24
-
-
Save alecharp/d8329a744333530e18e5d810645c1238 to your computer and use it in GitHub Desktop.
Simple groovy script to upgrade active plugins when new versions are available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jenkins.model.Jenkins.getInstance().getUpdateCenter().getSites().each { site -> | |
site.updateDirectlyNow(hudson.model.DownloadService.signatureCheck) | |
} | |
hudson.model.DownloadService.Downloadable.all().each { downloadable -> | |
downloadable.updateNow(); | |
} | |
def plugins = jenkins.model.Jenkins.instance.pluginManager.activePlugins.findAll { | |
it -> it.hasUpdate() | |
}.collect { | |
it -> it.getShortName() | |
} | |
println "Plugins to upgrade: ${plugins}" | |
long count = 0 | |
jenkins.model.Jenkins.instance.pluginManager.install(plugins, false).each { f -> | |
f.get() | |
println "${++count}/${plugins.size()}.." | |
} | |
if(plugins.size() != 0 && count == plugins.size()) { | |
jenkins.model.Jenkins.instance.safeRestart() | |
} |
I have made some work starting from this script. I made it detect plugins warnings or if any of them get deprecated before performing the update.
I have created a Jenkins pipeline that invokes the Groovy script and returns an alert if warnings or deprecated plugins are detected.
here is a link to the scripts
https://gist.github.com/taherbs/6d03b4d56ac4f1e7a119e64cf5d17f4c
Thank you @alecharp for the inspiration 🤘
@alecharp: This script is great. It would be really helpful to modify the script to check if there is any way to upgrade only the plugins which have no compatibility warnings with the current Jenkins version.
Does this fork not solve it?
Thanks for this! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@alecharp, can you share more about using the Docker image to have the latest Jenkins WAR and plugins? Could it be that you flush all existing JARs/plugins and keep appdata before updating the image?