Skip to content

Commit

Permalink
Extract "uninstall of deprecated plugins" into separate groovy file
Browse files Browse the repository at this point in the history
  • Loading branch information
fredg02 committed Oct 27, 2023
1 parent 1d56096 commit 20fea16
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
33 changes: 33 additions & 0 deletions groovy/cli/uninstall-deprecated-plugins.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// check update center for updates
jenkins.model.Jenkins.getInstance().getUpdateCenter().getSites().each { site ->
site.updateDirectlyNow(hudson.model.DownloadService.signatureCheck)
}

// Find plugins that are deprecated
def deprecated_plugins = jenkins.model.Jenkins.instance.pluginManager.activePlugins.findAll {
it -> it.isDeprecated()
}.collect {
it -> it.getShortName()
}

println " Found ${deprecated_plugins.size()} plugins that are deprecated."
println " " + deprecated_plugins

// uninstall deprecated plugins
println " Uninstalling deprecated plugins..."
long counter = 0
deprecated_plugins.each{
jenkins.model.Jenkins.instance.pluginManager.getPlugin(it).doDoUninstall()
println " ${++counter}/${deprecated_plugins.size()}.."
}

// safe restart

println " Restarting safely..."
println ""

if(deprecated_plugins.size() != 0 && counter == deprecated_plugins.size()) {
//TODO: set restart reason
// doQuietDown(boolean block, int timeout, String reason) ??
jenkins.model.Jenkins.instance.safeRestart()
}
18 changes: 0 additions & 18 deletions groovy/cli/update-jenkins-plugins.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,6 @@ jenkins.model.Jenkins.instance.pluginManager.install(plugins, false).each { f ->
println " ${++count}/${plugins.size()}.."
}

// Find plugins that are deprecated
def deprecated_plugins = jenkins.model.Jenkins.instance.pluginManager.activePlugins.findAll {
it -> it.isDeprecated()
}.collect {
it -> it.getShortName()
}

println " Found ${deprecated_plugins.size()} plugins that are deprecated."
println " " + deprecated_plugins

// uninstall deprecated plugins
println " Uninstalling deprecated plugins..."
long counter = 0
deprecated_plugins.each{
jenkins.model.Jenkins.instance.pluginManager.getPlugin(it).doDoUninstall()
println " ${++counter}/${deprecated_plugins.size()}.."
}

// safe restart

println " Restarting safely..."
Expand Down

0 comments on commit 20fea16

Please sign in to comment.