1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-16 11:09:33 +02:00

init script for resolving plugins

This commit is contained in:
Marcus Holl 2019-03-28 17:04:08 +01:00
parent 80f14ff9a2
commit db3507d57a

42
resolvePlugins.groovy Normal file
View File

@ -0,0 +1,42 @@
import jenkins.model.Jenkins
def stepCallMapping = new groovy.json.JsonSlurper().parseText(new File(System.getenv()['calls']).text)
def stepPluginMapping = [:]
println "[INFO] Resolving plugins ..."
for(def step in stepCallMapping) {
def resolvedPlugins = [:]
for(def call in step.value) {
def resolvedPlugin = resolvePlugin(call)
if (! resolvedPlugin) resolvedPlugin = 'UNIDENTIFIED'
if(resolvedPlugins[resolvedPlugin] == null)
resolvedPlugins[resolvedPlugin] = (Set)[]
resolvedPlugins[resolvedPlugin] << call
stepPluginMapping.put(step.key,resolvedPlugins)
}
}
def result = System.getenv()['result']
new File(result).write(new groovy.json.JsonOutput().toJson(stepPluginMapping))
println "[INFO] plugins resolved. Result: ${result}."
def resolvePlugin(call) {
def plugins = Jenkins.get().pluginManager.getPlugins()
def s = new org.jenkinsci.plugins.workflow.cps.Snippetizer()
def pDescs = s.getQuasiDescriptors(false)
for(def pd in pDescs) {
if(pd.getSymbol() == call)
return pd.real.plugin?.shortName
}
return null
}