Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonio-petricca/2cd7ac97b0e156fca4a085c44903c129 to your computer and use it in GitHub Desktop.
Save antonio-petricca/2cd7ac97b0e156fca4a085c44903c129 to your computer and use it in GitHub Desktop.
Simple groovy script to upgrade active plugins when new versions are available
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()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment