How do I analyse plugins and dependencies for an instance?

Article ID:216351528
2 minute readKnowledge base

Issue

  • You are removing the unused plugin in your Jenkins environment. You are not sure about the required plugins and its dependencies.

  • How can I troubleshoot plugins-related issues?

  • How can I retrieve the dependencies of a certain plugin in my instance?

Environment

  • CloudBees Jenkins Enterprise

  • CloudBees Jenkins Operations Center

Resolution

Starting with 1.633, the Plugin Manager UI prevent users from enabling/disabling/uninstalling plugins at the "wrong" time (see JENKINS-23150).

How to determine if a plugin is in use helps to understand where and how plugins are used in your instance. In particular, it helps to identify the plugins that are not or no longer used.

The Script Console can be used as a complement to analyse plugins and their dependencies. Following are basic but useful scripts to manage plugins via the Script Console.

  1. List of Plugins in Groovy

    The following Groovy displays the list of Failed plugins on your instance.

         jenkins.model.Jenkins.instance.getPluginManager().getFailedPlugins().each {
             println "${it.getShortName()} (${it.getVersion()})}"
     }

    The following script displays the list of Pinned plugins on your instance.

     jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
             .findAll { plugin -> plugin.isPinned() }
             .each {
                 println "${it.getShortName()} (${it.getVersion()})}"
     }

    The same snippet can be used to get the list of plugins that are Bundled, Disabled, Inactive, Deleted or even Forced by Pinning to a lower version. For advanced usage, please have a look at the java documentation of PluginManager and PluginWrapper.

  2. List of Plugins and Dependencies in Groovy

    The following Groovy script displays the list of plugins installed on your instance and their dependencies.

     def plugins = jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
     plugins.each {
             println "${it.getShortName()} (${it.getVersion()}) - ${it.getDependencies()}"
     }

    The following Groovy script displays the list of dependencies for a particular plugin, cloudbees-license for example, installed on your instance.

     def pluginByName = jenkins.model.Jenkins.instance.getPluginManager().getPlugin('cloudbees-license');
     println "${pluginByName.getShortName()} (${pluginByName.getVersion()}) - ${pluginByName.getDependencies()}"

    The following Groovy script displays the list of dependants (upward) of a particular plugin, cloudbees-license for example, installed on your instance.

     jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
             .findAll {
                 plugin -> plugin.getDependencies().find {
                     dependency -> "cloudbees-license".equals(dependency.shortName)
                 }
             }.each {
                 println "${it.getShortName()} (${it.getVersion()})"
             }