2018-01-29 17:47:22 +02:00
|
|
|
import com.cloudbees.groovy.cps.NonCPS
|
2018-02-01 13:57:25 +02:00
|
|
|
|
|
|
|
import com.sap.piper.ConfigurationLoader
|
|
|
|
import com.sap.piper.ConfigurationMerger
|
2018-01-29 17:47:22 +02:00
|
|
|
|
2018-02-01 13:57:25 +02:00
|
|
|
import groovy.transform.Field
|
|
|
|
|
2018-02-02 15:50:26 +02:00
|
|
|
@Field def STEP_NAME = 'checksPublishResults'
|
2018-01-31 17:56:18 +02:00
|
|
|
|
2018-01-29 17:47:22 +02:00
|
|
|
/**
|
2018-02-02 15:50:26 +02:00
|
|
|
* checksPublishResults
|
2018-01-29 17:47:22 +02:00
|
|
|
*
|
|
|
|
* @param others document all parameters
|
|
|
|
*/
|
2018-01-30 14:15:08 +02:00
|
|
|
def call(Map parameters = [:]) {
|
2018-02-01 13:57:25 +02:00
|
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
|
|
|
def script = parameters.script
|
|
|
|
if (script == null)
|
|
|
|
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
|
|
|
prepareDefaultValues script: script
|
|
|
|
|
|
|
|
Map configurationKeys = [
|
|
|
|
'aggregation': [
|
|
|
|
'active': null,
|
|
|
|
'healthy': null,
|
|
|
|
'unHealthy': null,
|
|
|
|
'thresholds': [
|
|
|
|
'fail': ['all': null,'low': null,'normal': null,'high': null],
|
|
|
|
'unstable': ['all': null,'low': null,'normal': null,'high': null]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'tasks': [
|
|
|
|
'pattern': null,
|
|
|
|
'low': null,
|
|
|
|
'normal': null,
|
|
|
|
'high': null,
|
|
|
|
'archive': null,
|
|
|
|
'active': null,
|
|
|
|
'healthy': null,
|
|
|
|
'unHealthy': null,
|
|
|
|
'thresholds': [
|
|
|
|
'fail': ['all': null,'low': null,'normal': null,'high': null],
|
|
|
|
'unstable': ['all': null,'low': null,'normal': null,'high': null]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'pmd': [
|
|
|
|
'pattern': null,
|
|
|
|
'archive': null,
|
|
|
|
'active': null,
|
|
|
|
'healthy': null,
|
|
|
|
'unHealthy': null,
|
|
|
|
'thresholds': [
|
|
|
|
'fail': ['all': null,'low': null,'normal': null,'high': null],
|
|
|
|
'unstable': ['all': null,'low': null,'normal': null,'high': null]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'cpd': [
|
|
|
|
'pattern': null,
|
|
|
|
'archive': null,
|
|
|
|
'active': null,
|
|
|
|
'healthy': null,
|
|
|
|
'unHealthy': null,
|
|
|
|
'thresholds': [
|
|
|
|
'fail': ['all': null,'low': null,'normal': null,'high': null],
|
|
|
|
'unstable': ['all': null,'low': null,'normal': null,'high': null]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'findbugs': [
|
|
|
|
'pattern': null,
|
|
|
|
'archive': null,
|
|
|
|
'active': null,
|
|
|
|
'healthy': null,
|
|
|
|
'unHealthy': null,
|
|
|
|
'thresholds': [
|
|
|
|
'fail': ['all': null,'low': null,'normal': null,'high': null],
|
|
|
|
'unstable': ['all': null,'low': null,'normal': null,'high': null]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'checkstyle': [
|
|
|
|
'pattern': null,
|
|
|
|
'archive': null,
|
|
|
|
'active': null,
|
|
|
|
'healthy': null,
|
|
|
|
'unHealthy': null,
|
|
|
|
'thresholds': [
|
|
|
|
'fail': ['all': null,'low': null,'normal': null,'high': null],
|
|
|
|
'unstable': ['all': null,'low': null,'normal': null,'high': null]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'eslint': [
|
|
|
|
'pattern': null,
|
|
|
|
'archive': null,
|
|
|
|
'active': null,
|
|
|
|
'healthy': null,
|
|
|
|
'unHealthy': null,
|
|
|
|
'thresholds': [
|
|
|
|
'fail': ['all': null,'low': null,'normal': null,'high': null],
|
|
|
|
'unstable': ['all': null,'low': null,'normal': null,'high': null]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'pylint': [
|
|
|
|
'pattern': null,
|
|
|
|
'archive': null,
|
|
|
|
'active': null,
|
|
|
|
'healthy': null,
|
|
|
|
'unHealthy': null,
|
|
|
|
'thresholds': [
|
|
|
|
'fail': ['all': null,'low': null,'normal': null,'high': null],
|
|
|
|
'unstable': ['all': null,'low': null,'normal': null,'high': null]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'archive': null
|
|
|
|
]
|
|
|
|
final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, STEP_NAME)
|
|
|
|
final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, STEP_NAME)
|
|
|
|
prepare(parameters)
|
|
|
|
Map configuration = ConfigurationMerger.mergeDeepStructure(parameters, configurationKeys, stepConfiguration, configurationKeys, stepDefaults)
|
|
|
|
|
|
|
|
def doArchive = configuration.get('archive')
|
2018-01-29 17:29:00 +02:00
|
|
|
// JAVA
|
2018-02-01 13:57:25 +02:00
|
|
|
report('PmdPublisher', configuration.get('pmd'), doArchive)
|
|
|
|
report('DryPublisher', configuration.get('cpd'), doArchive)
|
|
|
|
report('FindBugsPublisher', configuration.get('findbugs'), doArchive)
|
|
|
|
report('CheckStylePublisher', configuration.get('checkstyle'), doArchive)
|
2018-01-29 17:29:00 +02:00
|
|
|
// JAVA SCRIPT
|
2018-02-01 13:57:25 +02:00
|
|
|
reportWarnings('JSLint', configuration.get('eslint'), doArchive)
|
2018-01-29 17:29:00 +02:00
|
|
|
// PYTHON
|
2018-02-01 13:57:25 +02:00
|
|
|
reportWarnings('PyLint', configuration.get('pylint'), doArchive)
|
|
|
|
// GENERAL
|
|
|
|
reportTasks(configuration.get('tasks'))
|
|
|
|
aggregate(configuration.get('aggregation'))
|
2018-01-29 17:29:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def aggregate(settings){
|
2018-02-01 13:57:25 +02:00
|
|
|
if (settings.active) {
|
2018-01-29 17:29:00 +02:00
|
|
|
def options = createCommonOptionsMap('AnalysisPublisher', settings)
|
|
|
|
// publish
|
|
|
|
step(options)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 13:57:25 +02:00
|
|
|
def reportTasks(settings){
|
|
|
|
if (settings.active) {
|
|
|
|
def options = createCommonOptionsMap('TasksPublisher', settings)
|
|
|
|
options.put('pattern', settings.get('pattern'))
|
|
|
|
options.put('high', settings.get('high'))
|
|
|
|
options.put('normal', settings.get('normal'))
|
|
|
|
options.put('low', settings.get('low'))
|
|
|
|
// publish
|
|
|
|
step(options)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def report(publisherName, settings, doArchive){
|
|
|
|
if (settings.active) {
|
|
|
|
def pattern = settings.get('pattern')
|
2018-02-01 09:22:12 +02:00
|
|
|
def options = createCommonOptionsMap(publisherName, settings)
|
2018-01-30 14:14:05 +02:00
|
|
|
options.put('pattern', pattern)
|
2018-01-29 17:29:00 +02:00
|
|
|
// publish
|
|
|
|
step(options)
|
|
|
|
// archive check results
|
2018-02-01 13:57:25 +02:00
|
|
|
archiveResults(doArchive && settings.get('archive'), pattern, true)
|
2018-01-29 17:29:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 13:57:25 +02:00
|
|
|
def reportWarnings(parserName, settings, doArchive){
|
|
|
|
if (settings.active) {
|
|
|
|
def pattern = settings.get('pattern')
|
2018-01-29 17:29:00 +02:00
|
|
|
def options = createCommonOptionsMap('WarningsPublisher', settings)
|
|
|
|
options.put('parserConfigurations', [[
|
|
|
|
parserName: parserName,
|
2018-01-30 14:14:05 +02:00
|
|
|
pattern: pattern
|
2018-01-29 17:29:00 +02:00
|
|
|
]])
|
|
|
|
// publish
|
|
|
|
step(options)
|
|
|
|
// archive check results
|
2018-02-01 13:57:25 +02:00
|
|
|
archiveResults(doArchive && settings.get('archive'), pattern, true)
|
2018-01-29 17:29:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:15:49 +02:00
|
|
|
@NonCPS
|
2018-02-01 13:57:25 +02:00
|
|
|
def isMap(object){
|
|
|
|
return object in Map
|
2018-01-29 17:29:00 +02:00
|
|
|
}
|
|
|
|
|
2018-01-30 14:15:49 +02:00
|
|
|
@NonCPS
|
2018-02-05 14:48:39 +02:00
|
|
|
def toMap(parameter){
|
2018-02-01 13:57:25 +02:00
|
|
|
if(isMap(parameter))
|
|
|
|
parameter.put('active', true)
|
2018-02-05 14:48:39 +02:00
|
|
|
else if(Boolean.TRUE.equals(parameter))
|
2018-02-01 13:57:25 +02:00
|
|
|
parameter = [active: true]
|
2018-02-05 14:48:39 +02:00
|
|
|
else if(Boolean.FALSE.equals(parameter))
|
2018-02-01 13:57:25 +02:00
|
|
|
parameter = [active: false]
|
2018-02-05 14:48:39 +02:00
|
|
|
else
|
|
|
|
parameter = [:]
|
2018-02-01 13:57:25 +02:00
|
|
|
return parameter
|
2018-01-29 17:29:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def archiveResults(archive, pattern, allowEmpty){
|
|
|
|
if(archive){
|
2018-02-01 13:57:25 +02:00
|
|
|
echo "[${STEP_NAME}] archive ${pattern}"
|
2018-01-29 17:29:00 +02:00
|
|
|
archiveArtifacts artifacts: pattern, allowEmptyArchive: allowEmpty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:15:49 +02:00
|
|
|
@NonCPS
|
2018-01-30 11:06:35 +02:00
|
|
|
def createCommonOptionsMap(publisherName, settings){
|
2018-01-30 14:15:49 +02:00
|
|
|
Map result = [:]
|
2018-02-01 13:57:25 +02:00
|
|
|
def thresholds = settings.get('thresholds')
|
|
|
|
def fail = thresholds.get('fail')
|
|
|
|
def unstable = thresholds.get('unstable')
|
2018-01-29 17:29:00 +02:00
|
|
|
|
2018-01-30 11:06:35 +02:00
|
|
|
result.put('$class', publisherName)
|
2018-02-01 13:57:25 +02:00
|
|
|
result.put('healthy', settings.get('healthy'))
|
|
|
|
result.put('unHealthy', settings.get('unHealthy'))
|
2018-01-29 17:29:00 +02:00
|
|
|
result.put('canRunOnFailed', true)
|
2018-02-01 13:57:25 +02:00
|
|
|
result.put('failedTotalAll', '' + fail.get('all'))
|
|
|
|
result.put('failedTotalHigh', '' + fail.get('high'))
|
|
|
|
result.put('failedTotalNormal', '' + fail.get('normal'))
|
|
|
|
result.put('failedTotalLow', '' + fail.get('low'))
|
|
|
|
result.put('unstableTotalAll', '' + unstable.get('all'))
|
|
|
|
result.put('unstableTotalHigh', '' + unstable.get('high'))
|
|
|
|
result.put('unstableTotalNormal', '' + unstable.get('normal'))
|
|
|
|
result.put('unstableTotalLow', '' + unstable.get('low'))
|
2018-01-29 17:29:00 +02:00
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
2018-02-01 13:57:25 +02:00
|
|
|
|
|
|
|
@NonCPS
|
|
|
|
def prepare(parameters){
|
|
|
|
// ensure tool maps are initialized
|
2018-02-05 14:48:39 +02:00
|
|
|
parameters.aggregation = toMap(parameters.aggregation)
|
2018-02-01 13:57:25 +02:00
|
|
|
parameters.tasks = toMap(parameters.tasks)
|
|
|
|
parameters.pmd = toMap(parameters.pmd)
|
|
|
|
parameters.cpd = toMap(parameters.cpd)
|
|
|
|
parameters.findbugs = toMap(parameters.findbugs)
|
|
|
|
parameters.checkstyle = toMap(parameters.checkstyle)
|
|
|
|
parameters.eslint = toMap(parameters.eslint)
|
|
|
|
parameters.pylint = toMap(parameters.pylint)
|
|
|
|
return parameters
|
|
|
|
}
|