mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
use configuration framework
This commit is contained in:
parent
134d8e0b50
commit
c5188ef1cd
@ -1,7 +1,13 @@
|
||||
import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
import com.sap.piper.ConfigurationLoader
|
||||
import com.sap.piper.ConfigurationMerger
|
||||
import com.sap.piper.JsonUtils
|
||||
import com.sap.piper.Utils
|
||||
|
||||
def getStepName(){return 'checkResultsPublish'}
|
||||
import groovy.transform.Field
|
||||
|
||||
@Field def STEP_NAME = 'checkResultsPublish'
|
||||
|
||||
/**
|
||||
* checkResultsPublish
|
||||
@ -9,69 +15,160 @@ def getStepName(){return 'checkResultsPublish'}
|
||||
* @param others document all parameters
|
||||
*/
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors (stepName: getStepName(), stepParameters: parameters) {
|
||||
// GENERAL
|
||||
def tasks = parameters.get('tasks', false)
|
||||
def aggregation = parameters.get('aggregation', [:])
|
||||
def doArchive = parameters.get('archive', false)
|
||||
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')
|
||||
// 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)
|
||||
report('PmdPublisher', configuration.get('pmd'), doArchive)
|
||||
report('DryPublisher', configuration.get('cpd'), doArchive)
|
||||
report('FindBugsPublisher', configuration.get('findbugs'), doArchive)
|
||||
report('CheckStylePublisher', configuration.get('checkstyle'), doArchive)
|
||||
// JAVA SCRIPT
|
||||
def eslint = parameters.get('eslint', false)
|
||||
reportWarnings('JSLint', configuration.get('eslint'), doArchive)
|
||||
// PYTHON
|
||||
def pylint = parameters.get('pylint', false)
|
||||
|
||||
// report TODOs
|
||||
reportTasks(tasks, '**/*.java')
|
||||
// report PMD
|
||||
report('PmdPublisher', pmd, '**/target/pmd.xml', doArchive)
|
||||
// report CPD
|
||||
report('DryPublisher', cpd, '**/target/cpd.xml', doArchive)
|
||||
// report Findbugs
|
||||
report('FindBugsPublisher', findbugs, '**/target/findbugsXml.xml, **/target/findbugs.xml', doArchive)
|
||||
// report Checkstyle
|
||||
report('CheckStylePublisher', checkstyle, '**/target/checkstyle-result.xml', doArchive)
|
||||
// report ESLint
|
||||
reportWarnings('JSLint', eslint, '**/eslint.xml', doArchive)
|
||||
// report PyLint
|
||||
reportWarnings('PyLint', pylint, '**/pylint.log', doArchive)
|
||||
|
||||
// aggregate results
|
||||
aggregate(aggregation)
|
||||
reportWarnings('PyLint', configuration.get('pylint'), doArchive)
|
||||
// GENERAL
|
||||
reportTasks(configuration.get('tasks'))
|
||||
aggregate(configuration.get('aggregation'))
|
||||
}
|
||||
}
|
||||
|
||||
def aggregate(settings){
|
||||
if (!Boolean.FALSE.equals(settings)) {
|
||||
settings = asMap(settings)
|
||||
if (settings.active) {
|
||||
def options = createCommonOptionsMap('AnalysisPublisher', settings)
|
||||
// publish
|
||||
step(options)
|
||||
}
|
||||
}
|
||||
|
||||
def report(publisherName, settings, defaultPattern, doArchive){
|
||||
// exit if set to FALSE
|
||||
if(!Boolean.FALSE.equals(settings)){
|
||||
settings = asMap(settings)
|
||||
def pattern = settings.get('pattern', defaultPattern)
|
||||
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')
|
||||
def options = createCommonOptionsMap(publisherName, settings)
|
||||
options.put('pattern', pattern)
|
||||
// publish
|
||||
step(options)
|
||||
// archive check results
|
||||
archiveResults(doArchive && settings.get('archive', 'true'), pattern, true)
|
||||
archiveResults(doArchive && settings.get('archive'), pattern, true)
|
||||
}
|
||||
}
|
||||
|
||||
def reportWarnings(parserName, settings, defaultPattern, doArchive){
|
||||
// exit if set to FALSE
|
||||
if(!Boolean.FALSE.equals(settings)){
|
||||
settings = asMap(settings)
|
||||
def pattern = settings.get('pattern', defaultPattern)
|
||||
def reportWarnings(parserName, settings, doArchive){
|
||||
if (settings.active) {
|
||||
def pattern = settings.get('pattern')
|
||||
def options = createCommonOptionsMap('WarningsPublisher', settings)
|
||||
options.put('parserConfigurations', [[
|
||||
parserName: parserName,
|
||||
@ -80,21 +177,7 @@ def reportWarnings(parserName, settings, defaultPattern, doArchive){
|
||||
// publish
|
||||
step(options)
|
||||
// archive check results
|
||||
archiveResults(doArchive && settings.get('archive', 'true'), pattern, true)
|
||||
}
|
||||
}
|
||||
|
||||
def reportTasks(settings, defaultPattern){
|
||||
// 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)
|
||||
archiveResults(doArchive && settings.get('archive'), pattern, true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,25 +185,29 @@ def reportTasks(settings, defaultPattern){
|
||||
def ensureMap(parameters, name){
|
||||
def value = parameters.get(name, [:])
|
||||
if(!isMap(value))
|
||||
error "Expected parameter ${name} to be a map."
|
||||
error "[${STEP_NAME}] Expected parameter ${name} to be a map."
|
||||
return value
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def asMap(parameter){
|
||||
if(Boolean.TRUE.equals(parameter))
|
||||
return [:]
|
||||
return parameter
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def isMap(object){
|
||||
return object in Map
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def toMap(parameter, activeByDefault = false){
|
||||
if(isMap(parameter))
|
||||
parameter.put('active', true)
|
||||
else if(activeByDefault && !Boolean.FALSE.equals(parameter) || Boolean.TRUE.equals(parameter))
|
||||
parameter = [active: true]
|
||||
else
|
||||
parameter = [active: false]
|
||||
return parameter
|
||||
}
|
||||
|
||||
def archiveResults(archive, pattern, allowEmpty){
|
||||
if(archive){
|
||||
echo "[${getStepName()}] archive ${pattern}"
|
||||
echo "[${STEP_NAME}] archive ${pattern}"
|
||||
archiveArtifacts artifacts: pattern, allowEmptyArchive: allowEmpty
|
||||
}
|
||||
}
|
||||
@ -128,22 +215,36 @@ def archiveResults(archive, pattern, allowEmpty){
|
||||
@NonCPS
|
||||
def createCommonOptionsMap(publisherName, settings){
|
||||
Map result = [:]
|
||||
def thresholds = ensureMap(settings, 'thresholds')
|
||||
def fail = ensureMap(thresholds, 'fail')
|
||||
def unstable = ensureMap(thresholds, 'unstable')
|
||||
def thresholds = settings.get('thresholds')
|
||||
def fail = thresholds.get('fail')
|
||||
def unstable = thresholds.get('unstable')
|
||||
|
||||
result.put('$class', publisherName)
|
||||
result.put('healthy', settings.get('healthy', ''))
|
||||
result.put('unHealthy', settings.get('unHealthy', ''))
|
||||
result.put('healthy', settings.get('healthy'))
|
||||
result.put('unHealthy', settings.get('unHealthy'))
|
||||
result.put('canRunOnFailed', true)
|
||||
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', ''))
|
||||
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'))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
def prepare(parameters){
|
||||
// ensure tool maps are initialized
|
||||
parameters.aggregation = toMap(parameters.aggregation, true)
|
||||
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user