1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/documentation/jenkins_workspace/Jenkinsfile

72 lines
1.9 KiB
Plaintext
Raw Normal View History

2019-03-29 17:54:01 +02:00
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import jenkins.model.Jenkins
2019-05-21 11:16:06 +02:00
unresolvableCalls = [
podTemplate:'kubernetes',
container: 'kubernetes',
docker: 'docker-plugin',
usernamePassword: 'credentials-binding',
string: 'credentials-binding',
file: 'credentials-binding',
]
2019-05-17 15:41:00 +02:00
node() {
stage('Resolve Plugins') {
try {
resolvePlugins()
} catch(Exception e) {
def result = System.getenv()['result']
new File(new File(result).getParentFile(), 'FAILURE').text = "${e.getMessage()}"
throw e
}
}
}
2019-03-29 17:54:01 +02:00
def resolvePlugins() {
def stepCallMapping = new 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)
2019-05-21 11:16:06 +02:00
if (! resolvedPlugin) {
resolvedPlugin = unresolvableCalls[call]
if(! resolvedPlugin) resolvedPlugin = 'UNIDENTIFIED'
}
2019-03-29 17:54:01 +02:00
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 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)
2019-05-17 14:52:27 +02:00
return pd.real.plugin?.shortName
2019-03-29 17:54:01 +02:00
}
return null
}