Bulk Promote Plugins to Latest in Custom Update Centers

Issue

  • I want to promote all plugins to the latest in a managed Update Center
  • I want to promote all plugins to the latest stored version in a managed Update Center

Environment

Resolution

The promotion of plugin version in a managed update center is manual. It is therefore be cumbersome to promote a large number plugins.

The solution is to use a groovy script to execute under Manage Jenkins > Script Console.

Example 1: Bulk promote all stored plugins to the “Latest Version”

The following groovy script promote all plugins currently stored in a managed updated center to “Latest Version”. Whenever a more recent version is pulled, it will be promoted.

(Replace the value myUpdateCenter by the full name of you update center)

import com.cloudbees.plugins.updatecenter.PluginData

// Example of an update center "myUpdateCenter" at root level
def updateCenterFullName = "myUpdateCenter"

jenkins.model.Jenkins.instance.getItemByFullName("${updateCenterFullName}").getPluginsData().each { PluginData pluginData ->
    if(pluginData.getVersions() != null && !pluginData.getVersions().isEmpty()) {
        println "Promoting '${pluginData.getName()}' to latest (latestVersion: '${pluginData.getVersions().firstKey()}')"
        pluginData.setPromotedVersion(PluginData.LATEST_VERSION_STRING)
    } else {
        println "(Plugin '${pluginData.getName()}' is not pulled yet. Not promoting)"
    }
}
return

Example 2: Bulk promote all stored plugins to the current latest version

The following groovy script promote all plugins currently stored in a managed updated center to the latest version in store:

(Replace the value myUpdateCenter by the full name of you update center)

import com.cloudbees.plugins.updatecenter.PluginData

// Example of an update center "myUpdateCenter" at root level
def updateCenterFullName = "myUpdateCenter"

jenkins.model.Jenkins.instance.getItemByFullName("${updateCenterFullName}").getPluginsData().each { PluginData pluginData ->
    if(pluginData.getVersions() != null && !pluginData.getVersions().isEmpty()) {
        println "Promoting '${pluginData.getName()}' to version '${pluginData.getVersions().lastKey()}'"
        pluginData.setPromotedVersion("${pluginData.getVersions().lastKey()}")
    } else {
        println "(Plugin '${pluginData.getName()}' is not pulled yet. Not promoting)"
    }
}
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.