2018-01-29 17:47:22 +02:00
|
|
|
import com.cloudbees.groovy.cps.NonCPS
|
|
|
|
import com.sap.piper.Utils
|
|
|
|
|
2018-01-31 17:56:18 +02:00
|
|
|
def getStepName(){return 'checkResultsPublish'}
|
|
|
|
|
2018-01-29 17:47:22 +02:00
|
|
|
/**
|
|
|
|
* checkResultsPublish
|
|
|
|
*
|
|
|
|
* @param others document all parameters
|
|
|
|
*/
|
2018-01-30 14:15:08 +02:00
|
|
|
def call(Map parameters = [:]) {
|
2018-01-31 17:56:18 +02:00
|
|
|
handlePipelineStepErrors (stepName: getStepName(), stepParameters: parameters) {
|
2018-01-29 17:29:00 +02:00
|
|
|
// GENERAL
|
|
|
|
def tasks = parameters.get('tasks', false)
|
|
|
|
def aggregation = parameters.get('aggregation', [:])
|
|
|
|
def doArchive = parameters.get('archive', false)
|
|
|
|
// JAVA
|
|
|
|
def pmd = parameters.get('pmd', false)
|
|
|
|
def cpd = parameters.get('cpd', false)
|
|
|
|
def findbugs = parameters.get('findbugs', false)
|
|
|
|
def checkstyle = parameters.get('checkstyle', false)
|
|
|
|
// JAVA SCRIPT
|
|
|
|
def eslint = parameters.get('eslint', false)
|
|
|
|
// PYTHON
|
|
|
|
def pylint = parameters.get('pylint', false)
|
|
|
|
|
|
|
|
// report TODOs
|
2018-01-30 14:14:37 +02:00
|
|
|
reportTasks(tasks, '**/*.java')
|
2018-01-29 17:29:00 +02:00
|
|
|
// report PMD
|
2018-01-30 14:14:37 +02:00
|
|
|
report('PmdPublisher', pmd, '**/target/pmd.xml', doArchive)
|
2018-01-29 17:29:00 +02:00
|
|
|
// report CPD
|
2018-01-30 14:14:37 +02:00
|
|
|
report('DryPublisher', cpd, '**/target/cpd.xml', doArchive)
|
2018-01-29 17:29:00 +02:00
|
|
|
// report Findbugs
|
2018-01-30 14:14:37 +02:00
|
|
|
report('FindBugsPublisher', findbugs, '**/target/findbugsXml.xml, **/target/findbugs.xml', doArchive)
|
2018-01-29 17:29:00 +02:00
|
|
|
// report Checkstyle
|
2018-01-30 14:14:37 +02:00
|
|
|
report('CheckStylePublisher', checkstyle, '**/target/checkstyle-result.xml', doArchive)
|
2018-01-29 17:29:00 +02:00
|
|
|
// report ESLint
|
2018-01-30 16:26:54 +02:00
|
|
|
reportWarnings('JSLint', eslint, '**/eslint.xml', doArchive)
|
2018-01-29 17:29:00 +02:00
|
|
|
// report PyLint
|
2018-01-30 14:14:37 +02:00
|
|
|
reportWarnings('PyLint', pylint, '**/pylint.log', doArchive)
|
2018-01-29 17:29:00 +02:00
|
|
|
|
|
|
|
// aggregate results
|
|
|
|
aggregate(aggregation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def aggregate(settings){
|
|
|
|
if (!Boolean.FALSE.equals(settings)) {
|
|
|
|
settings = asMap(settings)
|
|
|
|
def options = createCommonOptionsMap('AnalysisPublisher', settings)
|
|
|
|
// publish
|
|
|
|
step(options)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:14:37 +02:00
|
|
|
def report(stepName, settings, defaultPattern, doArchive){
|
2018-01-29 17:29:00 +02:00
|
|
|
// exit if set to FALSE
|
|
|
|
if(!Boolean.FALSE.equals(settings)){
|
|
|
|
settings = asMap(settings)
|
2018-01-30 14:14:05 +02:00
|
|
|
def pattern = settings.get('pattern', defaultPattern)
|
2018-01-29 17:29:00 +02:00
|
|
|
def options = createCommonOptionsMap(stepName, 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
|
|
|
|
archiveResults(doArchive && settings.get('archive', 'true'), pattern, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:14:37 +02:00
|
|
|
def reportWarnings(parserName, settings, defaultPattern, doArchive){
|
2018-01-29 17:29:00 +02:00
|
|
|
// exit if set to FALSE
|
|
|
|
if(!Boolean.FALSE.equals(settings)){
|
|
|
|
settings = asMap(settings)
|
2018-01-30 14:14:05 +02:00
|
|
|
def pattern = settings.get('pattern', defaultPattern)
|
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
|
|
|
|
archiveResults(doArchive && settings.get('archive', 'true'), pattern, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:14:37 +02:00
|
|
|
def reportTasks(settings, defaultPattern){
|
2018-01-29 17:29:00 +02:00
|
|
|
// exit if set to FALSE
|
|
|
|
if(!Boolean.FALSE.equals(settings)){
|
|
|
|
settings = asMap(settings)
|
|
|
|
def options = createCommonOptionsMap('TasksPublisher', settings)
|
|
|
|
options.put('pattern', settings.get('pattern', defaultPattern))
|
|
|
|
options.put('high', settings.get('high', 'FIXME'))
|
|
|
|
options.put('normal', settings.get('normal', 'TODO,REVISE,XXX'))
|
|
|
|
options.put('low', settings.get('low', ''))
|
|
|
|
// publish
|
|
|
|
step(options)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:15:49 +02:00
|
|
|
@NonCPS
|
2018-01-29 17:29:00 +02:00
|
|
|
def ensureMap(parameters, name){
|
|
|
|
def value = parameters.get(name, [:])
|
|
|
|
if(!isMap(value))
|
|
|
|
error "Expected parameter ${name} to be a map."
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:15:49 +02:00
|
|
|
@NonCPS
|
2018-01-29 17:29:00 +02:00
|
|
|
def asMap(parameter){
|
|
|
|
if(Boolean.TRUE.equals(parameter))
|
|
|
|
return [:]
|
|
|
|
return parameter
|
|
|
|
}
|
|
|
|
|
2018-01-30 14:15:49 +02:00
|
|
|
@NonCPS
|
2018-01-29 17:29:00 +02:00
|
|
|
def isMap(object){
|
|
|
|
return object in Map
|
|
|
|
}
|
|
|
|
|
|
|
|
def archiveResults(archive, pattern, allowEmpty){
|
|
|
|
if(archive){
|
2018-01-31 17:56:18 +02:00
|
|
|
echo "[${getStepName()}] 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-01-29 17:29:00 +02:00
|
|
|
def thresholds = ensureMap(settings, 'thresholds')
|
|
|
|
def fail = ensureMap(thresholds, 'fail')
|
|
|
|
def unstable = ensureMap(thresholds, 'unstable')
|
|
|
|
|
2018-01-30 11:06:35 +02:00
|
|
|
result.put('$class', publisherName)
|
2018-01-29 17:29:00 +02:00
|
|
|
result.put('healthy', settings.get('healthy', ''))
|
|
|
|
result.put('unHealthy', settings.get('unHealthy', ''))
|
|
|
|
result.put('canRunOnFailed', true)
|
2018-01-30 16:26:54 +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
|
|
|
|
}
|