56

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 with another mature plugin (different name).

This needs to make sure no one/no job use those plugins or I need to notify them.

Are there any ways in configuration or somewhere in Jenkins system to know whether the plugin is used by any jobs ?

UPDATE 2013 Based on the answer below, I maintain the simple "plugin:keyword" mapping, like

plugin_keys = {
    "git":'scm class="hudson.plugins.git.GitSCM"',
    "copyartifact":"hudson.plugins.copyartifact.CopyArtifact",
        # and more      
}

And search the plugin keyword from the config.xml, all the information (plugins,jobs,config) can be fetched via jenkins remote API

it works for me.

UPDATE 2014.04.26 Later jenkins version, it seems the config.xml is changed to have plugin name there directly

Like

<com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.4">
<hudson.plugins.throttleconcurrents.ThrottleJobProperty plugin="throttle-concurrents@1.7.2">
<hudson.plugins.disk__usage.DiskUsageProperty plugin="disk-usage@0.18"/>
<scm class="hudson.plugins.git.GitSCM" plugin="git@1.4.1-SNAPSHOT">

Therefore I just check this plugin="<plugin name>" in config.xml, it works again

UPDATE 2014.05.05

See complete script in gist jenkins-stats.py

UPDATE 2018.6.7

There is plugin usage plugin support this (no REST API yet)

Larry Cai
  • 55,923
  • 34
  • 110
  • 156
  • Hi I am looking for the same solution. can you give more information on where you maintain the mapping and from where you run the script? Can you please share your complete script? Thanks – user1164061 Apr 25 '14 at 17:59
  • now the config.xml is updated with plugin information, in my case, it works enough, so I don't maintain extra list, see new updates. – Larry Cai Apr 26 '14 at 13:34
  • Hi, do you manually go through each config.xml or do you have a script to do that? If so, can you please share it? thanks! – user1164061 Apr 29 '14 at 21:11
  • 1
    see my gist for complete script, enjoy – Larry Cai May 05 '14 at 03:10
  • Thank you very much. Appreciate your help. – user1164061 May 05 '14 at 16:26
  • Hi Larry,can you explain how you are getting the complete list of used system plugins like Active directory etc? I do not understand from your script. If I look at the system's config.xml, it has few plugins in that, but its not a complete list. There are some plugins listed outside like for e.g hudson.plugins.timestamper.TimestamperConfig.xml etc. How do we find if these plugins are used or no? – user1164061 May 12 '14 at 18:15
  • It was not so complete in the script, and use there to discuss to make it clean here. – Larry Cai May 13 '14 at 02:55
  • Checking `plugin=` in config.xml for each job works fine for almost of the plugins, but there are few plugins like [Mask Password](https://wiki.jenkins-ci.org/display/JENKINS/Mask+Passwords+Plugin) which just have this line. `` – vikas027 Jan 18 '16 at 05:56
  • thank for the information, probably we need propose to jenkins community to get this in better way. – Larry Cai Jan 20 '16 at 11:58

4 Answers4

21

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!

coffeebreaks
  • 3,787
  • 1
  • 26
  • 25
  • nice information, and it seems getting the class name is also tricky. – Larry Cai Aug 11 '13 at 13:38
  • unfortunately, latest url in answer this is broken – Vitalii Elenhaupt Aug 03 '15 at 16:20
  • instead of the find-xargs-grep command you could also just use grep directly: `grep Unity3dBuilder $JENKINS_HOME/jobs/*/config.xml` – msa Jan 12 '17 at 07:36
  • 3
    @msa this depends on the number of config files you have on your disk. You might hit a `grep: arg list too long` error if you have lots of jobs. – coffeebreaks Jan 13 '17 at 11:08
  • Another addition to the grep command, which I find most useful, because of ease: `find . -maxdepth 4 -name config.xml | xargs -d '\n' grep Unity3dBuilder` maxdepth 4, because you may have folder-type jobs - like the Jenkins _Pipeline Multibranch Plugin_ jobs. xargs -d '\n' to handle cases where the directory contains spaces. – Kutzi May 14 '18 at 14:00
  • you can use `grep -q` to ignore errors, `grep -i` to ignore case, and `grep -iq` to ignores errors and ignores case. – Eduardo Cuomo May 18 '18 at 21:59
14

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

Plugins used in pipeline scripts would not be listed normally as used by jobs, because they are used dynamically in Jenkinsfiles.

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
dragon788
  • 3,583
  • 1
  • 40
  • 49
  • 1
    nice, it will be better if it can have REST API supported. – Larry Cai Jun 07 '18 at 08:25
  • 5
    Plugins Usage Plugin isn't very useful IMO because it doesn't detect plugin usage from pipeline jobs. I installed this months ago and the Plugin only reports that 4/100 of my installed plugins are used and I know this to be false. Then I found their own docs admit this as well: "Plugins used in pipeline scripts would not be listed normally as used by jobs, because they are used dynamically in Jenkinsfiles." – timblaktu Mar 12 '20 at 02:23
  • Similar to the above comment, I see this isn't picking up usage in scripted jobs. "Warning: Scripted pipeline jobs are not detected by this plugin. Support for declarative pipeline jobs is experimental. Number of Jobs: 0" – Colm Bhandal Oct 11 '21 at 16:38
7

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"); 
  }
}
Community
  • 1
  • 1
Duff
  • 1,389
  • 1
  • 11
  • 21
  • thanks Duff ! I also inlined the scriplet (which I was also author of, so no copyright issue). – coffeebreaks Jan 20 '16 at 16:57
  • Hi @Duff I used abpve scipt but I didn't get which job is using whihc plugin I just got someting like this ```Key[type=configurationslicing.logstash.LogStashSlicer, annotation=[none]]``` – Dashrath Mundkar Sep 11 '20 at 16:32
0

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 {} \;
Florian Straub
  • 826
  • 9
  • 18