Thanks for sharing Robert. Did you upload it to the scriptler scripts page too?

Bruno P. Kinoshita
http://kinoshita.eti.br
http://tupilabs.com


>________________________________
> From: "Sandell, Robert" <[email protected]>
>To: "[email protected]" <[email protected]> 
>Sent: Tuesday, 6 November 2012 12:33 PM
>Subject: RE: Getting the jobs that are using plugin
> 
>The following Groovy script lists all jobs and what plugins are involved in 
>them.
>I'm not sure if It is catching all, but most of the common extension points 
>are there.
>
>//---------------------------------------------------------------------------------------
>import jenkins.model.*
>import hudson.model.*
>import hudson.matrix.*
>import java.util.*
>
>def jnks = Jenkins.getInstance()
>
>plugMgr = jnks.pluginManager
>
>void addPlugin(cl, plugs) {
>  wrapper = plugMgr.whichPlugin(cl.getClass())
>  if (wrapper != null) {
>    plugs.add(wrapper.getShortName())
>  }
>}
>
>jnks.getItems().each() {job ->
>  plugs = new HashSet()
>  if (job instanceof AbstractProject) {
>    addPlugin(job, plugs)
>    job.getProperties().each() {cl -> addPlugin(cl, plugs)}
>    job.getActions().each() {cl -> addPlugin(cl, plugs)}
>    addPlugin(job.getScm(), plugs)
>    job.getTriggers().each() {cl -> addPlugin(cl, plugs)}
>    job.getWidgets().each() {cl -> addPlugin(cl, plugs)}
>    job.getPublishersList().each() {cl -> addPlugin(cl, plugs)}
>    
>  }
>  if (job instanceof Project || job instanceof MatrixProject) {
>    job.getBuilders().each() {cl -> addPlugin(cl, plugs)}
>    job.getBuildWrappers().each() {cl -> addPlugin(cl, plugs)}
>  }
>  if (job instanceof MatrixProject) {
>    job.getAxes().each() {cl -> addPlugin(cl, plugs)}
>  }
>  println(job.getName())
>  plugs.each() {it -> println("\t" + it)}
>}
>//---------------------------------------------------------------------------------
>
>Robert Sandell
>Software Tools Engineer - SW Environment and Product Configuration
>Sony Mobile Communications
>
>
>> -----Original Message-----
>> From: [email protected] [mailto:jenkinsci-
>> [email protected]] On Behalf Of Bruno P. Kinoshita
>> Sent: den 5 november 2012 21:01
>> To: [email protected]
>> Subject: Re: Getting the jobs that are using plugin
>> 
>> Not sure if this is the best way, but if your plugin adds Actions to
>> builds, then you would need to scan the builds of the job, and try to
>> retrieve your plug-in's action. Like below (not tested):
>> 
>> perform(AbstractBuild build) {
>>    Action myAction = build.getAction(MyPluginAction.class);
>>    if(myAction != null) {
>>      // this build is using my plug-in
>>    }
>> }
>> 
>> As for knowing if it is using other plug-ins, you can add a dependency
>> to that other plug-in in your plug-in, and use the approach described
>> above. Although you have to take care to only use that plug-in's
>> classes if the user has the plug-in installed. Like below (again, not
>> tested).
>> 
>> Plugin myPlugin = Jenkins.getInstance().getPlugin("my-super-duper-
>> plugin");
>> if(myPlugin != null) {
>>   // It means I can use my plug-in classes, without raising
>> ClassNotFoundException
>>   // Find if this job/build is using the plug-in
>>   //...
>> }
>> 
>> Again, not sure if that's the best way for doing this, but hope that
>> helps :o)
>> 
>> Bruno P. Kinoshita
>> http://kinoshita.eti.br
>> http://tupilabs.com
>> 
>> 
>> >________________________________
>> > From: Edding <[email protected]>
>> >To: [email protected]
>> >Sent: Monday, 5 November 2012 2:04 PM
>> >Subject: Getting the jobs that are using plugin
>> >
>> >
>> >Hello,
>> >
>> >
>> >I am writing a Jenkins plugin and I need a way to know which jobs are
>> currently using the plugin, or it may help too knowing which plugins
>> are being used by a job.
>> >
>> >
>> >Any ideas?
>> >
>> >
>> >Thanks in advance
>> >
>> >
>
>
> 

Reply via email to