我怎么知道该插件是否被jenkins中的任何作业使用 [英] how can I know whether the plugin is used by any jobs in jenkins

查看:115
本文介绍了我怎么知道该插件是否被jenkins中的任何作业使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins有600多个插件,在实际系统中,我们习惯于安装许多插件.

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.

Jenkins系统中是否有任何配置或方法可以知道该插件是否被任何作业使用?

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

UPDATE 2013 根据以下答案,我维护简单的"plugin:keyword"映射,例如

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      
}

并从config.xml中搜索plugin关键字,所有信息(插件,作业,配置)都可以通过

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

对我有用.

更新2014.04.26 后来的jenkins版本,似乎config.xml更改为直接在其中具有插件名称

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

喜欢

<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">

因此,我只需在config.xml中检查此plugin="<plugin name>",它就可以再次工作

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

更新2014.05.05

请参见要点中的完整脚本 jenkins-stats.py

See complete script in gist jenkins-stats.py

更新2018.6.7

插件使用插件支持此功能(尚无REST API)

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

推荐答案

以下是找到该信息的两种方法.

Here are 2 ways to find that information.

最简单的方法可能是grep作业配置文件:

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

例如当您知道插件的类名(或包名)(例如org.jenkinsci.plugins.unity3d.Unity3dBuilder)时:

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"); 
  }
}

(从我的原始列表JenkinsExtensions提交到 http://scriptlerweb.appspot.com 的内联式清单中,该列表似乎已关闭)

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

别忘了备份!

这篇关于我怎么知道该插件是否被jenkins中的任何作业使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆