mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +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.cloudbees.groovy.cps.NonCPS
|
||||||
|
|
||||||
|
import com.sap.piper.ConfigurationLoader
|
||||||
|
import com.sap.piper.ConfigurationMerger
|
||||||
|
import com.sap.piper.JsonUtils
|
||||||
import com.sap.piper.Utils
|
import com.sap.piper.Utils
|
||||||
|
|
||||||
def getStepName(){return 'checkResultsPublish'}
|
import groovy.transform.Field
|
||||||
|
|
||||||
|
@Field def STEP_NAME = 'checkResultsPublish'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checkResultsPublish
|
* checkResultsPublish
|
||||||
@ -9,69 +15,160 @@ def getStepName(){return 'checkResultsPublish'}
|
|||||||
* @param others document all parameters
|
* @param others document all parameters
|
||||||
*/
|
*/
|
||||||
def call(Map parameters = [:]) {
|
def call(Map parameters = [:]) {
|
||||||
handlePipelineStepErrors (stepName: getStepName(), stepParameters: parameters) {
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
||||||
// GENERAL
|
def script = parameters.script
|
||||||
def tasks = parameters.get('tasks', false)
|
if (script == null)
|
||||||
def aggregation = parameters.get('aggregation', [:])
|
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||||
def doArchive = parameters.get('archive', false)
|
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
|
// JAVA
|
||||||
def pmd = parameters.get('pmd', false)
|
report('PmdPublisher', configuration.get('pmd'), doArchive)
|
||||||
def cpd = parameters.get('cpd', false)
|
report('DryPublisher', configuration.get('cpd'), doArchive)
|
||||||
def findbugs = parameters.get('findbugs', false)
|
report('FindBugsPublisher', configuration.get('findbugs'), doArchive)
|
||||||
def checkstyle = parameters.get('checkstyle', false)
|
report('CheckStylePublisher', configuration.get('checkstyle'), doArchive)
|
||||||
// JAVA SCRIPT
|
// JAVA SCRIPT
|
||||||
def eslint = parameters.get('eslint', false)
|
reportWarnings('JSLint', configuration.get('eslint'), doArchive)
|
||||||
// PYTHON
|
// PYTHON
|
||||||
def pylint = parameters.get('pylint', false)
|
reportWarnings('PyLint', configuration.get('pylint'), doArchive)
|
||||||
|
// GENERAL
|
||||||
// report TODOs
|
reportTasks(configuration.get('tasks'))
|
||||||
reportTasks(tasks, '**/*.java')
|
aggregate(configuration.get('aggregation'))
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def aggregate(settings){
|
def aggregate(settings){
|
||||||
if (!Boolean.FALSE.equals(settings)) {
|
if (settings.active) {
|
||||||
settings = asMap(settings)
|
|
||||||
def options = createCommonOptionsMap('AnalysisPublisher', settings)
|
def options = createCommonOptionsMap('AnalysisPublisher', settings)
|
||||||
// publish
|
// publish
|
||||||
step(options)
|
step(options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def report(publisherName, settings, defaultPattern, doArchive){
|
def reportTasks(settings){
|
||||||
// exit if set to FALSE
|
if (settings.active) {
|
||||||
if(!Boolean.FALSE.equals(settings)){
|
def options = createCommonOptionsMap('TasksPublisher', settings)
|
||||||
settings = asMap(settings)
|
options.put('pattern', settings.get('pattern'))
|
||||||
def pattern = settings.get('pattern', defaultPattern)
|
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)
|
def options = createCommonOptionsMap(publisherName, settings)
|
||||||
options.put('pattern', pattern)
|
options.put('pattern', pattern)
|
||||||
// publish
|
// publish
|
||||||
step(options)
|
step(options)
|
||||||
// archive check results
|
// archive check results
|
||||||
archiveResults(doArchive && settings.get('archive', 'true'), pattern, true)
|
archiveResults(doArchive && settings.get('archive'), pattern, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def reportWarnings(parserName, settings, defaultPattern, doArchive){
|
def reportWarnings(parserName, settings, doArchive){
|
||||||
// exit if set to FALSE
|
if (settings.active) {
|
||||||
if(!Boolean.FALSE.equals(settings)){
|
def pattern = settings.get('pattern')
|
||||||
settings = asMap(settings)
|
|
||||||
def pattern = settings.get('pattern', defaultPattern)
|
|
||||||
def options = createCommonOptionsMap('WarningsPublisher', settings)
|
def options = createCommonOptionsMap('WarningsPublisher', settings)
|
||||||
options.put('parserConfigurations', [[
|
options.put('parserConfigurations', [[
|
||||||
parserName: parserName,
|
parserName: parserName,
|
||||||
@ -80,21 +177,7 @@ def reportWarnings(parserName, settings, defaultPattern, doArchive){
|
|||||||
// publish
|
// publish
|
||||||
step(options)
|
step(options)
|
||||||
// archive check results
|
// archive check results
|
||||||
archiveResults(doArchive && settings.get('archive', 'true'), pattern, true)
|
archiveResults(doArchive && settings.get('archive'), 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,25 +185,29 @@ def reportTasks(settings, defaultPattern){
|
|||||||
def ensureMap(parameters, name){
|
def ensureMap(parameters, name){
|
||||||
def value = parameters.get(name, [:])
|
def value = parameters.get(name, [:])
|
||||||
if(!isMap(value))
|
if(!isMap(value))
|
||||||
error "Expected parameter ${name} to be a map."
|
error "[${STEP_NAME}] Expected parameter ${name} to be a map."
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonCPS
|
|
||||||
def asMap(parameter){
|
|
||||||
if(Boolean.TRUE.equals(parameter))
|
|
||||||
return [:]
|
|
||||||
return parameter
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonCPS
|
@NonCPS
|
||||||
def isMap(object){
|
def isMap(object){
|
||||||
return object in Map
|
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){
|
def archiveResults(archive, pattern, allowEmpty){
|
||||||
if(archive){
|
if(archive){
|
||||||
echo "[${getStepName()}] archive ${pattern}"
|
echo "[${STEP_NAME}] archive ${pattern}"
|
||||||
archiveArtifacts artifacts: pattern, allowEmptyArchive: allowEmpty
|
archiveArtifacts artifacts: pattern, allowEmptyArchive: allowEmpty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,22 +215,36 @@ def archiveResults(archive, pattern, allowEmpty){
|
|||||||
@NonCPS
|
@NonCPS
|
||||||
def createCommonOptionsMap(publisherName, settings){
|
def createCommonOptionsMap(publisherName, settings){
|
||||||
Map result = [:]
|
Map result = [:]
|
||||||
def thresholds = ensureMap(settings, 'thresholds')
|
def thresholds = settings.get('thresholds')
|
||||||
def fail = ensureMap(thresholds, 'fail')
|
def fail = thresholds.get('fail')
|
||||||
def unstable = ensureMap(thresholds, 'unstable')
|
def unstable = thresholds.get('unstable')
|
||||||
|
|
||||||
result.put('$class', publisherName)
|
result.put('$class', publisherName)
|
||||||
result.put('healthy', settings.get('healthy', ''))
|
result.put('healthy', settings.get('healthy'))
|
||||||
result.put('unHealthy', settings.get('unHealthy', ''))
|
result.put('unHealthy', settings.get('unHealthy'))
|
||||||
result.put('canRunOnFailed', true)
|
result.put('canRunOnFailed', true)
|
||||||
result.put('failedTotalAll', '' + fail.get('all', ''))
|
result.put('failedTotalAll', '' + fail.get('all'))
|
||||||
result.put('failedTotalHigh', '' + fail.get('high', ''))
|
result.put('failedTotalHigh', '' + fail.get('high'))
|
||||||
result.put('failedTotalNormal', '' + fail.get('normal', ''))
|
result.put('failedTotalNormal', '' + fail.get('normal'))
|
||||||
result.put('failedTotalLow', '' + fail.get('low', ''))
|
result.put('failedTotalLow', '' + fail.get('low'))
|
||||||
result.put('unstableTotalAll', '' + unstable.get('all', ''))
|
result.put('unstableTotalAll', '' + unstable.get('all'))
|
||||||
result.put('unstableTotalHigh', '' + unstable.get('high', ''))
|
result.put('unstableTotalHigh', '' + unstable.get('high'))
|
||||||
result.put('unstableTotalNormal', '' + unstable.get('normal', ''))
|
result.put('unstableTotalNormal', '' + unstable.get('normal'))
|
||||||
result.put('unstableTotalLow', '' + unstable.get('low', ''))
|
result.put('unstableTotalLow', '' + unstable.get('low'))
|
||||||
|
|
||||||
return result
|
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