how can I know whether the plugin is used by any jobs in jenkins

后端 未结 4 603
天涯浪人
天涯浪人 2021-01-31 07:39

Jenkins had 600+ plugins, in the real system, we are used to install lots of plugins.

And sometimes, we want to remove some plugins to make system more clean or replace

相关标签:
4条回答
  • 2021-01-31 08:01

    I wrote this parameterized Jenkins job that searches config files. You only need to know what tags the plugin generates in the config file and to use that tag's name as parameter needle:

    cd  $JENKINS_HOME
    cd jobs
    echo searching for $needle
    find . -name config.xml -type f -exec grep $needle /dev/null {} \;
    
    0 讨论(0)
  • 2021-01-31 08:05

    As of early 2018 there is a "Plugins Usage Plugin" that gives you a nice list of the plugins and where they are used. We've noticed that depending on the system sometimes it doesn't seems to catch all the plugins, but it gives a really lovely list of the plugins and all jobs related to a specific plugin in an expandable list.

    https://plugins.jenkins.io/plugin-usage-plugin

    0 讨论(0)
  • 2021-01-31 08:15

    I can't comment because I don't have enough reputation, but if I could, I would point out that the broken link provided by coffeebreaks for the small scriplet script mentioned in the accepted answer can be found on the Internet Archive, at this link:

    https://web.archive.org/web/20131103111754/http://scriptlerweb.appspot.com/script/show/97001

    In case that link breaks, here is the content of the script:

    import jenkins.model.*;
    import hudson.ExtensionFinder;
    
    List<ExtensionFinder> finders = Jenkins.instance.getExtensionList(ExtensionFinder.class);
    
    for (finder in finders) {
      println(">>> " + finder);
      if (finder instanceof hudson.ExtensionFinder.GuiceFinder) {
        println(finder.annotations.size());
        for (key in finder.annotations.keySet()) {
           println(key);
        }
      } else if (finder instanceof ruby.RubyExtensionFinder) {
        println(finder.parsedPlugins.size());
        for (plugin in finder.parsedPlugins) {
          for (extension in plugin.extensions) {
            println("ruby wrapper for " + extension.instance.clazz);
          }
        }
      } else if (finder instanceof hudson.cli.declarative.CLIRegisterer) {
        println(finder.discover(Jenkins.instance));
        for (extension in finder.discover(Jenkins.instance)) {
          println("CLI wrapper for " + extension.instance.class);
          // not sure what to do with those      
        }
      } else {
        println("UNKNOWN FINDER TYPE"); 
      }
    }
    
    0 讨论(0)
  • 2021-01-31 08:16

    Here are 2 ways to find that information.

    The easiest is probably to to grep the job config files:

    E.g. when you know the class name (or package name) of your plugin (e.g. org.jenkinsci.plugins.unity3d.Unity3dBuilder):

    find $JENKINS_HOME/jobs/ -name config.xml -maxdepth 2 | xargs grep Unity3dBuilder
    

    Another is to use something like the scriptler plugin, but then you need more information about where the plugin is used in the build.

    import hudson.model.*
    import hudson.maven.*
    import hudson.tasks.*
    
    for(item in Hudson.instance.items) {
        //println("JOB : "+item.name);
        for (builder in item.builders){
          if (builder instanceof org.jenkinsci.plugins.unity3d.Unity3dBuilder) {
            println(">>" + item.name.padRight(50, " ") + "\t UNITY3D BUILDER with " + builder.unity3dName);
          }
        }
      }
    }
    

    Update: here's a small scriplet script that might ease you finding the relevant class names. It can certainly be improved:

    import jenkins.model.*;
    import hudson.ExtensionFinder;
    
    List<ExtensionFinder> finders = Jenkins.instance.getExtensionList(ExtensionFinder.class);
    
    for (finder in finders) {
      println(">>> " + finder);
      if (finder instanceof hudson.ExtensionFinder.GuiceFinder) {
        println(finder.annotations.size());
        for (key in finder.annotations.keySet()) {
           println(key);
        }
      } else if (finder instanceof ruby.RubyExtensionFinder) {
        println(finder.parsedPlugins.size());
        for (plugin in finder.parsedPlugins) {
          for (extension in plugin.extensions) {
            println("ruby wrapper for " + extension.instance.clazz);
          }
        }
      } else if (finder instanceof hudson.cli.declarative.CLIRegisterer) {
        println(finder.discover(Jenkins.instance));
        for (extension in finder.discover(Jenkins.instance)) {
          println("CLI wrapper for " + extension.instance.class);
          // not sure what to do with those      
        }
      } else {
        println("UNKNOWN FINDER TYPE"); 
      }
    }
    

    (inlined scriplet from my original listJenkinsExtensions submission to http://scriptlerweb.appspot.com which seems down)

    Don't forget to backup!

    0 讨论(0)
提交回复
热议问题